Analyze logs with awk

Go directly to the shell command:

awk 'BEGIN{index2=1;sum=0;}{if($0~"1003"){index2=NR;sum++;print "第"NR"行: " ,$0;} else if (NR<index2+3 ) {print $0} else if (NR==index2+3){print "\n\n\n"}}END{print "共搜索到"sum"条"}' error.log.2018-04-17.log

Command Explanation : 



Command execution result : 



 

The content of store_error.log.2018-04-17.log is as follows:

100300,aaa
aaaaaaaaaaabbbb
111111111111111
1
1
1
1
1
1003,bbb
bbbbbbbbbbbbbb
2222222222222222
2
2
2
2
2
2
1003.ccc
cccccccccccccccc
33333333333333333
3
3
3
3
3

 

 

awk parameter description :

-f (lowercase): specify the awk script;

-F (uppercase): specify the delimiter;

-v: specify variable

 

refer to:

http://hw1287789687.iteye.com/blog/2419653

http://hw1287789687.iteye.com/blog/2419658

https://www.tuicool.com/articles/2mqmYbe

https://my.oschina.net/huangweiindex/blog/1799244

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326108430&siteId=291194637
awk