Operating System - HP-UX
1752578 Members
4152 Online
108788 Solutions
New Discussion юеВ

Re: Help me out on this.!!Find "ERROR" in the log file

 
E.Gopi Kannan
Occasional Advisor

Help me out on this.!!Find "ERROR" in the log file

Hi All,

Help me out on this.!!

Example log file. say file.log

dd-mm-yyyy fsagsgsfgf ERROR:gsdagasfgsdfgaga

I want to know,

how to find the jan 1st 2011 with only ""ERROR" on the above mentioned log file.
6 REPLIES 6
Ivan Krastev
Honored Contributor

Re: Help me out on this.!!Find "ERROR" in the log file

Use simple grep twice:

grep "01-01-2011" filename | grep ERROR


regards,
ivan
E.Gopi Kannan
Occasional Advisor

Re: Help me out on this.!!Find "ERROR" in the log file

thanks..!!
Ismail Azad
Esteemed Contributor

Re: Help me out on this.!!Find "ERROR" in the log file

Hi,

Similar to the pharoah's way but just a little different.

cat filename | grep -e 1/1/2011 -e ERROR

That should work too. Or you can also try egrep.

Regards
Ismail Azad

Read, read and read... Then read again until you read "between the lines".....
Dennis Handly
Acclaimed Contributor

Re: Help me out on this.!!Find "ERROR" in the log file

>Ismail: Similar to the pharoah's way but just a little different.

This isn't similar, this is wrong, it does an OR, the OP wants an AND.

A better solution and without the evil cat:
grep "01-01-2011.*ERROR" filename
Ismail Azad
Esteemed Contributor

Re: Help me out on this.!!Find "ERROR" in the log file

Hi,

> jan 1st 2011 with only ""ERROR".

Yup more than ERROR, important word there was "only". Was thinking in terms of "OR". Sorry bout that.

Regards
Ismail Azad
Read, read and read... Then read again until you read "between the lines".....
Trond Haugen
Honored Contributor

Re: Help me out on this.!!Find "ERROR" in the log file

Previous responses are good so I just wanted to add that since the date is at teh beginning of the lines you could use:

grep "^01-01-2011" file.log | grep ERROR
Regards,
Trond Haugen
LinkedIn