替换换行符 sed [英] replacing newline sed
本文介绍了替换换行符 sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 sed 命令替换一行中的 \n?
How to replace \n from a line using sed command?
推荐答案
很恶心,因为 sed 通常一次处理一行:
It's gross, because sed normally processes a line at a time:
sed -e :a -e N -e 's/\n/ /' -e ta input.txt
这样更好:
tr '\n' ' ' < input.txt
我选择用空格替换换行符.tr 只能替换为单个字符(或使用 -d 选项删除).
I chose to replace the newline with a space. tr can only replace by a single character (or delete with the -d option).
灵活简单:
perl -ne 'chomp;print $_," "' input.txt
" 是你想要的任何东西来代替换行符.
Where " " is whatever you want in place of the newline.
这篇关于替换换行符 sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文