grep two strings in a file..

Hello All,
I have a big file about 1000 lines. Now i am trying to grep a particular string and printing the lines from the string.

say for example in 500th line i have the date as "Mon Wed 14 20:15:24 2010". now i in my case i need to grep the combination of the strings "Mon Wed 14" and the other string "2010". i need to ignore the time among the whole string. so in one command i need to grep the two strings and ignore the time alone.

Please help in this regard. Thanks in advance.

Raju

sed -n -e '/Mon Wed 14 [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\} 2010/p' file1

cheers,
Devaraj Takhellambam

You can use the grep command as follows

grep "Mon Wed 14.*2010" filename

So this will match the combination of the strings Mon Wed 15 and 2010 from that lines.

Try:

grep 'Mon Wed 14 [0-2][0-9]:[0-5][0-9]:[0-5][0-9] 2010' file

try

cat file | grep "Mon Wed 14 20" | grep "2010"

Few points:

  1. Useless use of cat. No need of cat there
  2. It fail for conditions such as
    Mon Wed 14 20 12:10:10 2009 djflsdjfjdsjjf2010

You can use the following command,which will work for any kind of date.

egrep "[A-Z][a-z]{2} [A-Z][a-z]{2} [0-9]{2} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [0-9]{0,4}" file

Hi Thillai selvan,
Thanks a bunch. it worked like charm...

Thanks
Raju