网上很多关于tr命令的介绍都用到这个功能
tr -s '\n'
#都解释说是删除空行
这个就是网上的.
我想各位读者可以试试第一行是空行的情况,看看还能删除吗?
然后再试试空行在某行的下面的情况
这叫有图有真相,看明白了吧,傻了吧!
解释下,其实-s的man tr就明白了
-s, --squeeze-repeats
replace each input sequence of a repeated character that is
listed in SET1 with a single occurrence of that character
replace each input sequence of a repeated character that is
listed in SET1 with a single occurrence of that character
所以网上的东西 一定好试试想想,尽量 还是看看man吧,毕竟这个权威。
-s 其实是删除连续的重复字符,而只保留最前面的一个。所以上面我们的结果就是保留了第一个\n.
这个才是真正删除空行.
转载于:https://blog.51cto.com/linuxgp/605777