[root@m01 scripts]# cat range.log
hellowordis a linuxer.
device: {
oo
helloword
no sql
this is log
niu niu
}
helloword
device: {
helloword
no sql
this is log
niu niu
}
helloword
device: {
helloword
no sql
this is log
niu niu
}
device: {
helloword
no sql
this is log
niu niu
}
[root@m01 scripts]# awk '/{/,/}/ {if(/helloword/) i++}END{print i}' range.log
4
步骤分析
awk '
/{/ , /}/{ #条件 匹配 {} 里面的内容
if(/helloword/) #二次过滤 找出{}中内容且是helloword的
i++ #计数
}
END{
print i #显示结果
}' range.txt