Ответ в комментарии Филиппоса
You can't. Sorry to say that, but as soon as it's on hfs+, it's no "backup" anymore. Even without considering the problems with the linux hfs driver, backup on hfs(+) is not a good idea. I've been a mac lover for decades, but hfs(+) has always been a pain for me. TimeMachine is a great tool, but every now and then you have to start anew due to some hfs problems. I hope for apfs and pray that I don't need my backup until then.
С bash вы можете использовать встроенную функцию printf
, просто будьте осторожны с %
символами:
doublequoted="line0'field0\nline1\tfield1\"%s"
printf -v interpreted "${doublequoted//%/%%}"
, затем
$ declare -p doublequoted interpreted
declare -- doublequoted="line0'field0\\nline1\\tfield1\"%s"
declare -- interpreted="line0'field0
line1 field1\"%s"
$ printf "%s" "$interpreted" | od -c
0000000 l i n e 0 ' f i e l d 0 \n l i n
0000020 e 1 \t f i e l d 1 " % s
0000034
Единственный инструмент, который приходит на ум (и широко доступен ), это sed
, и он не совсем красив.
sed ':a;N;$!ba;s/\n/\\n/g;s/\t/\\t/g'
Итак...
$ cat file
line0'field0
line1 field1"
$ sed ':a;N;$!ba;s/\n/\\n/g;s/\t/\\t/g' file
line0'field0\nline1\tfield1"
Со ссылкой на:https://stackoverflow.com/questions/1251999/how-can-i-replace-a-newline-n-using-sed
Если я правильно понял вопрос, я думаю, вы ищете что-то вроде этого (это в bash}:
$ doublequoted="line0'field0\nline1\tfield1\""
$ foo="$(echo -e "${doublequoted//\\/\\\\}")"
$ echo $foo
line0'field0\nline1\tfield1"
Если я вас неправильно понял, уточните, что вы ищете.