tr command - how to replace the string “\n” with an actual newline (\n)

蹲街弑〆低调 提交于 2019-12-18 13:53:09

问题


I would like to use the tr command to replace all occurrences of the string "\n" with a new line (\n).

I tried tr '\\n' '\n' but this just seems to match any '\' and any 'n'


回答1:


Here's how to do it with sed:

sed 's/\\n/\n/g'

Example usage:

To replace all occurrences of \n in a file in-place:

sed -i 's/\\n/\n/g' input_filename

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


来源:https://stackoverflow.com/questions/13610639/tr-command-how-to-replace-the-string-n-with-an-actual-newline-n

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!