[英]Sed line to remove unnecessary spaces is deleting line ends too & other strange new line issue
I have to deal with an output from a command. 我必须处理命令的输出。 Just plain text.
只是纯文本。 What I want is to remove unnecessary spaces by using
我想要的是通过使用删除不必要的空间
sed 's/ */ /g'
But it's doing it wrong - it seems to remove new line characters as well... 但这做错了-似乎也删除了换行符...
The other problem is about the $ character representing the 'new line'. 另一个问题是关于代表“换行”的$字符。
When I'm writing sth like this: 当我写这样的东西时:
sed 's/$/FOO/g'
It is really replacing all the new line chars with the word FOO. 它实际上是用FOO代替所有新的换行符。 So its basically like:
所以它基本上像:
text
text
text
Is converted to 转换为
textFOOtextFOOtext
The problem starts when 2 new lines occur. 当出现2条新线时,问题开始。 The text:
文本:
text
text
Is converted to: 转换为:
textFOOFOOtext
BUT -- absolutely no SED line is able to convert the 2 new lines into one. 但是-绝对没有SED线能够将2条新线转换为一条。 I tried everything I found on the web.
我尝试了在网上找到的所有内容。
How do I remove that additional new line? 如何删除该新行?
Check if this helps: 检查是否有帮助:
tr -s ' ' < File
This will change multiple spaces to single space, if thats what u want 如果您要的话,这会将多个空格更改为单个空格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.