[["QUALITY",**"AVM",200**,610865413,1,0,7,2,-1],[5,0,0,0,0,2],
[0.998286,0,1,0,0],[0,0,0,0,0,0],["aq04rvtcmgff8"],
[["QUALITY",**"AVM",200**,610865413,1,0,7,2,-1],[5,0,0,0,0,2],
[0.998286,0,1,0,0],[0,0,0,0,0,0],["aq04rvtcmgff8"]
[["QUALITY",**"AVM",200**,610865413,1,0,7,2,-1],[5,0,0,0,0,2],
[0.998286,0,1,0,0],[0,0,0,0,0,0],["aq04rvtcmgff8"]
[["QUALITY","AVM”,100,610865413,1,0,7,2,-1]
This is the log i have. I want to grep the pattern as follow:
这是我的日志。我想要模式如下:
**"AVM",200** - In the above log, how many time this pattern comes. Result should be **3**
I have tried:
我努力了:
**grep "\"AVM\",200" <file> | wc -l** --> but its not giving perfect result
1 个解决方案
#1
2
If there is single match per line, use -c
option
如果每行有单个匹配项,请使用-c选项
grep -c '"AVM",200' log
If there are multiple matches, print one match per line and then count number of lines (depends on grep
implementation, not all have -o
option)
如果有多个匹配项,则每行打印一个匹配项,然后计算行数(取决于grep实现,不是所有都有-o选项)
grep -o '"AVM",200' log | wc -l
Or use GNU awk
to set the search string as record separator and use number of records to get count
或者使用GNU awk将搜索字符串设置为记录分隔符,并使用记录数来计算
awk -v RS='"AVM",200' 'END{print NR-1}' log
# to handle empty input as well
awk -v RS='"AVM",200' 'END{print (NR>1?NR-1:0)}'
Or count number of occurrences per line
或计算每行的出现次数
awk -F'"AVM",200' 'NF{total += NF-1} END{print total+0}' log
#1
2
If there is single match per line, use -c
option
如果每行有单个匹配项,请使用-c选项
grep -c '"AVM",200' log
If there are multiple matches, print one match per line and then count number of lines (depends on grep
implementation, not all have -o
option)
如果有多个匹配项,则每行打印一个匹配项,然后计算行数(取决于grep实现,不是所有都有-o选项)
grep -o '"AVM",200' log | wc -l
Or use GNU awk
to set the search string as record separator and use number of records to get count
或者使用GNU awk将搜索字符串设置为记录分隔符,并使用记录数来计算
awk -v RS='"AVM",200' 'END{print NR-1}' log
# to handle empty input as well
awk -v RS='"AVM",200' 'END{print (NR>1?NR-1:0)}'
Or count number of occurrences per line
或计算每行的出现次数
awk -F'"AVM",200' 'NF{total += NF-1} END{print total+0}' log