试试这个单行:
awk '/}/{f=1;next} $0 && f{f=0;next} !$0 && f{print "empty line found:"NR}' file
举个例子:
kent$ nl -ba file
1 foo
2 bar}
3
4 foo2
5
6
7 bar2{
8
9 }
10
11
12
13 eof
kent$ awk '/}/{f=1;next} $0 && f{f=0;next} !$0 && f{print "empty line found:"NR}' file
empty line found:3
empty line found:10
empty line found:11
empty line found:12
编辑
新更新的问题又脏又快:
awk '/}/{f=1;m=0;next} $0 && f{f=0;m=0;next} !$0 && f &&!m{m=1;next} m{print "empty line found:"NR}' file
新测试:
kent$ nl -ba file
1 foo
2 bar}
3
4 foo2
5
6
7 bar2{
8
9 }
10
11
12
13 blah{}
14
15
16
17
18 eof
kent$ awk '/}/{f=1;m=0;next} $0 && f{f=0;m=0;next} !$0 && f &&!m{m=1;next} m{print "empty line found:"NR}' file
empty line found:11
empty line found:12
empty line found:15
empty line found:16
empty line found:17