示例:
假设 nowcoder.txt 内容如下:
a b c d e f你的脚本应当输出:
3 5 7 9 10
#!/bin/bash #利用grep查找空行并打印(有冒号),然后用sed把冒号替换成空并打印 grep -n "^ $" nowcoder.txt | sed -n 's@\:@@p'
i=1;while read p; do if [[ $p == '' ]]; then echo $i; fi; ((i++)); done < nowcoder.txt
i=1;while read p; do if [ -z $p ]; then echo $i; fi; ((i++)); done < nowcoder.txt
awk '/^$/ {print NR}' nowcoder.txt
sed -n '/^$/=' nowcoder.txt
grep -n '^$' nowcoder.txt | awk -F: '{print $1}'
grep -n "^$" nowcoder.txt | sed -n 's/\://p'
grep -n "^$" nowcoder.txt | sed 's/\://g'
grep -n "^$" nowcoder.txt | sed "s@:@@g"
for num in {1..10}
do
if [ -z "$(awk "NR==$num" nowcoder.txt)" ]; then
echo "$num"
fi
done
#!/bin/bash
for i in $(awk '/^\s*$/{print NR}' nowcoder.txt)
do
echo $i
done