且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 sed 从传入流中删除换行符

更新时间:2023-02-19 15:54:07

要删除换行符,请使用 tr:

To remove newlines, use tr:

tr -d '
'

如果你想用一个空格替换每个换行符:

If you want to replace each newline with a single space:

tr '
' ' '

错误 ba: Event not found 来自 csh,是由于 csh 试图匹配历史列表中的 !ba.您可以转义 ! 并编写命令:

The error ba: Event not found is coming from csh, and is due to csh trying to match !ba in your history list. You can escape the ! and write the command:

sed ':a;N;$!ba;s/
/ /g'  # Suitable for csh only!!

但是 sed 是错误的工具,您***使用更合理地处理带引号的字符串的 shell.也就是停止使用csh,开始使用bash.

but sed is the wrong tool for this, and you would be better off using a shell that handles quoted strings more reasonably. That is, stop using csh and start using bash.