我想用更长的字符串替换每行中的 '\n'
字符,例如:"___\n"
。
当我尝试时:
$ cat /tmp/test.csv | sed ':a;N;$!ba;s/\n/____\n/g'
我得到以下输出
"00000";"29515470";"001";"001";"A6399000800";"";"";"-1";"142.72";"1.00";"1.00"____
"91930";"20029956";"001";"002";"A2128300018";"";"";"-1";"71.58";"1.00";"4.00"____
"91930";"20029962";"001";"003";"ZZ-OIL16";"";"";"-1";"14.48";"5.00";"3.00"____
"91930";"20029962";"001";"002";"A2661800009";"";"";"-1";"13.28";"1.00";"3.00"
最后一个 '\n' 没有被替换。
如何替换所有 \n
字符?
我发现了这个:
How can I replace a newline (\n) using sed?
, 但这个解决方案对我来说不好,因为它不处理最后一个 '\n'
字符。
最佳答案
使用sed
:
$ cat > foo
this
that
$ sed 's/$/__/g' foo
this__
that__
$ sed 's/$/__/g' foo | hexdump -C
00000000 74 68 69 73 5f 5f 0a 74 68 61 74 5f 5f 0a |this__.that__.|
0a
最后。
附言。注意缺少 useless cat
.
关于linux - 如何替换 CSV 文件中的所有换行符,包括最后一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50532333/