Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要用 "\n (双引号后跟换行符) 替换一行中的每个 \n。
这应该有效。但它什么也没做。也不报错。任何线索任何人?
sed -i 's/\n/\"\n/' filename
之前,该文件包含:
line 1 line 2
之后,它包含完全相同的内容。
谢谢
行不能包含\n,因为\n是行之间的分隔符。sed一次只在一行上运行,并且换行符不包含在其中。
\n
sed
如果你想在每行的末尾添加一个字符,请使用正则$表达式:
$
sed -i 's/$/"/' filename
尝试以下操作:
用于$表示行尾。
使用 awk
awk '{$0=$0"\""}1' filename