我使用SED一个grep命令切滤波器,基本上变成我的输出与此类似壳牌删除制表符/空格
this line 1
this line 2
another line 3
another line 4
我试图得到一个输出不含空格的东西之间线条和线条前面所以它看起来像
this line 1
this line 2
another line 3
another line 4
我想添加another |过滤
我使用SED一个grep命令切滤波器,基本上变成我的输出与此类似壳牌删除制表符/空格
this line 1
this line 2
another line 3
another line 4
我试图得到一个输出不含空格的东西之间线条和线条前面所以它看起来像
this line 1
this line 2
another line 3
another line 4
我想添加another |过滤
添加此过滤器,从行的开头删除空白和删除空行,注意它使用两个sed
命令,一个删除前导空格和另一个没有内容
| sed -e 's/^\s*//' -e '/^$/d'
删除线在the Wikipedia article for sed中有一个示例,它使用d命令删除空白行或只包含空格的行,我的解决方案使用转义序列\s
来匹配任何空白字符(空格,制表符等),这里是维基百科示例:
sed -e '/^ *$/d' inputFileName
(whateverproducesthisoutput)|sed -E 's/^[[:space:]]+//'|grep -v '^$'
(取决于你sed
,可以取代[[:space:]]
与\s
)。
我会做到这一点,短而简单:
sed 's: ::g'
在你的命令的末尾添加这一点,所有的空格会噗。例如试试这个命令:
cat/proc/meminfo | sed 's: ::g'
使用grep "^." filename
而printing.Here,以任何字符的行匹配,使得空行冷落删除空行。
这是在尝试上面列表中更高的答案之后为我工作的第一个答案。 – k0pernikus