Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i do a grep count by using timestamp

How can I do a grep count by using timestamp?

Example: If I have a file in which I search a value xyz everytime. The file gets updated regularly.

20121912-07:15:55 abc cbfr xyz
20121912-07:16:40 mni cbfr xyz
-----------
-----------
-----------


20121912-08:15:55 gty cbfr xyz
20121912-08:20:55 jui uio xyz

I want to find out the occurences of xyz after 20121912-08:15:55 which in this case should be 2.

Doing a grep -c "xyz" filename reads the entire file and gives the result. I want to do it after the last update or using a timestamp.

like image 347
user1916191 Avatar asked Dec 19 '12 15:12

user1916191


1 Answers

try this one-liner:

awk '$NF=="xyz"&&$1>="20121912-08:15:55"{x++;}END{print x}' file
like image 189
Kent Avatar answered Sep 19 '22 12:09

Kent