题解 | #shell/bash去掉空行#
去掉空行
http://www.nowcoder.com/practice/0372acd5725d40669640fd25e9fb7b0f
同上一题,输出空行的行号,该题则删除空行
# grep 正则实现 grep -v '^$' nowcoder.txt cat nowcoder.txt | grep -v '^\s*$' # sed 命令正则 sed '/^\s*$/d' nowcoder.txt # awk 正则 awk '{if(! /^\s*$/) print $0}' nowcoder.txt cat nowcoder.txt | awk '{if(!/^\s*$/) print $0}' # tr命令首次接触 cat nowcoder.txt |tr -s "\n"