Text Parser

I am having a text file as follows

say server.txt

Date        Time          server      ip                error code
--------------------------------------------------------------------------
02/21/2008   18:10:14   server1  xxx.xxx.xxx.xxx    6
02/21/2008   08:10:14   server2  xxx.xxx.xxx.xxx    196
03/21/2008   21:10:14   server8  xxx.xxx.xxx.xxx    96
03/21/2008   12:10:14   server9  xxx.xxx.xxx.xxx    132
04/21/2008   06:10:14   server4  xxx.xxx.xxx.xxx    254
04/21/2008   18:10:14   server6  xxx.xxx.xxx.xxx    6

I need a script to write lines to new file which satisfy the below condition

if Date=02/21/2008 and server=server1 and error code=6 and ip=xxx.xxx.xxx.xxx then that line should be written to output.txt

Please let me know any script can satisfy all 4 condition strings in a line...

Thanks in advance

awk '{
if($1=="02/21/2008" && $3=="server1" && $4=="xxx.xxx.xxx.xxx " && $5==6)
print
}' filename

There is no error in using your awk, but no result. i see only a blank file. can u give more details.

Remove the extra space after the IP address ($4=="xxx.xxx.xxx.xxx " ) in the awk command.

It works perfectly fine.

This is wat i tried

this is the command i used
$ sh aaa.sh 02/21/2008 server1 xxx.xxx.xxx.xxx 6 input.txt

Hi ALL,

It Works fine :b:.

thanks to all.
:slight_smile:

wat will be the command for

awk '{if($1=="02/21/2008" or $1=="02/22/2008")print}input.txt

use || for or