tr命令-如何替换字符串"\ n"使用实际的换行符(\ n) [英] tr command - how to replace the string "\n" with an actual newline (\n)
本文介绍了tr命令-如何替换字符串"\ n"使用实际的换行符(\ n)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用tr
命令用新行(\ n)替换所有出现的字符串"\ n".
I would like to use the tr
command to replace all occurrences of the string "\n" with a new line (\n).
我尝试了tr '\\n' '\n'
,但这似乎与任何'\'和任何'n'
I tried tr '\\n' '\n'
but this just seems to match any '\' and any 'n'
推荐答案
以下是使用sed
的方法:
sed 's/\\n/\n/g'
示例用法:
要就地替换文件中所有出现的\n
:
To replace all occurrences of \n
in a file in-place:
sed -i 's/\\n/\n/g' input_filename
要通过管道替换所有出现的\n
,并将其保存到另一个文件中
To replace all occurrences of \n
through a pipe, and save into another file
cat file1 file2 file3 file4 | sed 's/\\n/\n/g' > output_file
这篇关于tr命令-如何替换字符串"\ n"使用实际的换行符(\ n)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文