2013-03-09 49 views
0

我试图用一个bash脚本,以确定我的代码,关闭}如何找到空行后}使用bash

我能够搜索和查找文本之后有一个以上的空行的地方使用该脚本:

TAGS="text" 
find "${SRCROOT}" \(-name "*.h" -or -name "*.m" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "\$match = 1 if s/($TAGS)/ error: \$1/; END { exit \$match; }" 

但我不知道如何搜索关闭}字符后出现的空行。我需要某种类型的正则表达式吗?

有人可以帮我把这些碎片放在一起吗?

编辑

为了澄清,它实际上是真正有用的发现只有在有一个以上的空行后}。

回答

1

尝试这一个班轮:

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 
+0

感谢您的回答!我编辑了我的问题,添加了一个我没有意识到我正在寻找的细节。我们如何调整你的答案,以便只显示}之后有多于一条空行的地方?谢谢! – Lizza 2013-03-09 20:32:24

+0

@Casper请参阅编辑答案 – Kent 2013-03-09 20:57:50