四种方法:
- grep 正则:匹配空行并删除 用-v(两种写法)
grep -v '^$' nowcoder.txt
cat nowcoder.txt | grep -v '^$'
- awk 正则:匹配不是空格的行全部输出
awk '{if(!/^$/)print $0}' nowcoder.txt
- sed 正则:匹配空格删除
sed '/^$/d' nowcoder.txt
- tr 删除相同符号\n
cat nowcoder.txt | tr -s "\n"
四种方法:
grep -v '^$' nowcoder.txt
cat nowcoder.txt | grep -v '^$'
awk '{if(!/^$/)print $0}' nowcoder.txt
sed '/^$/d' nowcoder.txt
cat nowcoder.txt | tr -s "\n"