替换换行sed

时间:2009-09-18 05:13:05

标签: sed replace

如何使用 sed 命令从一行替换 \ n

1 个答案:

答案 0 :(得分:9)

这很糟糕,因为sed通常一次处理一行:

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

这更好:

tr '\n' ' ' < input.txt

我选择用空格替换换行符。 tr只能替换为单个字符(或使用-d选项删除)。

灵活简单:

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

其中“”是您想要的任何代替换行符。

相关问题