我试图使用sed将文件中的多个空格替换为单个空格。
但是它会像下面那样分割每个字符。请让我知道问题出在哪里...
$ cat test.txt
iiHi Hello Hi
this is loga
$
$ cat test.txt | tr [A-Z] [a-z]|sed -e "s/ */ /g"
i i h i h e l l o h i
t h i s i s l o g a
您的sed
命令做错了事,因为它在“零个或多个空格”上匹配,这当然发生在每对字符之间!而不是s/ */ /g
你想要s/ */ /g
或s/ +/ /g
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句