我有一个文件如下。
Hi this is first line
this is second line
this is third line
预期是:
Hi this is first line
this is second line
this is third line
我用的是
cat file.txt | sed 's/ //g'
返回,
Hi this is first line
this is second line
this is third line
最佳答案
对于可移植的 sed 命令,使用这个:
sed 's/^[[:blank:]]*//' file
[[:blank:]]
匹配空格或制表符。
编辑:使用 awk 删除所有空格:
awk '{$1=$1}1' OFS= file
或 sed:
sed 's/[[:blank:]]*//g' file
关于linux - UNIX sed 命令不删除 cat 输出中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22204150/