我想使用 tr
命令将所有出现的字符串“\n”替换为新行 (\n)。
我试过 tr '\\n' '\n'
但这似乎匹配任何 '\' 和任何 'n'
最佳答案
下面是使用 sed
的方法:
sed 's/\\n/\n/g'
示例用法:
就地替换文件中所有出现的 \n
:
sed -i 's/\\n/\n/g' input_filename
通过管道替换所有出现的\n
,并保存到另一个文件中
cat file1 file2 file3 file4 | sed 's/\\n/\n/g' > output_file
关于linux - tr 命令 - 如何将字符串 "\n"替换为实际的换行符 (\n),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13610639/