user2647888
user2647888

Reputation: 721

How do i grep for this pattern

I have a file which has multiple lines of this pattern

20140604 02:05:51:142 INFO  M2F_F2M_Server - Number of messages in the Input Queue : "ANCDGBBBB" Count : 0
20140604 02:07:58:145 INFO  M2F_F2M_Server - Number of messages in the Input Queue : "ANCDGBBBB" Count : 8

I want to only grep for "20140604" date and as well as where count !=0

I tried the following command

grep '20140604' | grep -v 'Count : 0' XYZ.dat .  But with no use. 

Please help

Please note there can be other date entries also in the file like '20140607' but my concern is only of 20140604.

My sample output should only have :

20140604 02:07:58:145 INFO  M2F_F2M_Server - Number of messages in the Input Queue : "ANCDGBBBB" Count : 8

Upvotes: 0

Views: 53

Answers (2)

hek2mgl
hek2mgl

Reputation: 158280

You missed to pass the filename XYZ.dat to your first grep command. If you pass it, it should work. However, you can do the job with just a single grep command. Like this:

grep '^20140604.*Count : [^0].*$' XYZ.dat

Upvotes: 1

P.P
P.P

Reputation: 121427

An awk solution:

awk '$1==20140604 && $NF{print}' file

$1 is the first word and $NF (corresponding to count).

Upvotes: 3

Related Questions