replacing newline sed

扶醉桌前 提交于 2020-01-03 15:13:20

问题


How to replace \n from a line using sed command?


回答1:


It's gross, because sed normally processes a line at a time:

sed -e :a -e N -e 's/\n/ /' -e ta input.txt

This is nicer:

tr '\n' ' ' < input.txt

I chose to replace the newline with a space. tr can only replace by a single character (or delete with the -d option).

Flexible and simple:

perl -ne 'chomp;print $_," "' input.txt

Where " " is whatever you want in place of the newline.



来源:https://stackoverflow.com/questions/1442702/replacing-newline-sed

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