我正在尝试使用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; }" 但是我不确定如何搜索出现在结束}字符之后的空行。我需要某种正则表达式吗?
有没有人能帮我把这些拼装在一起?
编辑
为了清楚起见,如果只查找a }后面有多个空行的地方,这实际上会很有用。
发布于 2013-03-10 04:26:01
试试这一行:
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:17https://stackoverflow.com/questions/15315351
复制相似问题