user663724
user663724

Reputation:

grep count of a string with a filter condition

I need to do a grep count of a string with a filter condition .

The context is

Data will be genearetd in the below format in our log files

2013-05-17 10:06:40,693[qtp1957835280-12 Selector1] ERROR(CustomThread.java:<disconnect>:202)- onDisconnect: CustomThread [customerId=122, formattedId=testuser] reason : 1004, reasonMessage : closed

The log file is having data of all the previous days also (ie 17 , 16 , 15 , 14 , 13)

But i want to find the count of reason : 1004 for the present day that is 2013-05-17

If i execute grep -c 1004 application.log its giving me the count of the previous daya also

Please let me know is it possible to get the count of 1004 for the current day only

Upvotes: 1

Views: 229

Answers (2)

iruvar
iruvar

Reputation: 23394

try

 grep -c '^2013-05-17.*reason : 1004' file

Upvotes: 3

Alper
Alper

Reputation: 13250

Try

grep `date +%Y-%m-%d` file | grep -c 1004

Upvotes: 2

Related Questions