Grep a word and find its Count from log file for different times
A direct awk
:
awk '/^201[0-9].*:/{if (cont){print cont}cont=0;printf $0}/Error/{cont+=1}END{print cont}' infile
Explained code
:
awk '/^201[0-9].*:/{ # Timestamp pattern reached if (cont){ print cont # print previus timestamp } # counter if exists and not zero cont=0 # initialize actual timestamp counter printf $0 } # print timestamp WITHOUT linebreak /Error/{ # Error patter reached cont+=1 # Aaccumulated count } END{ print cont # print remainder counter }' infile