grep for pattern

hi

i hav a file containing the values as

RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241292536501rtmssrv1 20080508153812394 395 396 INTERNAL 1406 GMLC919440000857 SUCCESS0 1210241288197338
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241292536501rtmssrv1 20080508153812394 395 396 INTERNAL 1409 GMLC919490242288 SUCCESS0 1210241288197338
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241299342509rtmssrv1 2008050815381966 258 261 INTERNAL 928 GMLC919444395566 SUCCESS0 1210241288921341
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241310313520rtmssrv1 20080508153830394 395 396 INTERNAL 1410 GMLC919440000808 FAILURE1 1210241310267368
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241317531525rtmssrv1 2008050815383966 255 256 INTERNAL 910 GMLC919444395454 SUCCESS0 1210241314898375
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241317531525rtmssrv1 2008050815383966 255 256 INTERNAL 903 GMLC919444395462 SUCCESS0 1210241314898375
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241317531525rtmssrv1 2008050815383966 255 256 INTERNAL 907 GMLC919444395471 SUCCESS0 1210241314898375
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241317531525rtmssrv1 2008050815383966 255 256 INTERNAL 904 GMLC919444395480 SUCCESS0 1210241314898375
RTMS_LOCATION_CDR PERIODIC_LOCATION_REPORT 1210241317531525rtmssrv1 2008050815383966 255 256 INTERNAL 908 GMLC919444395452 SUCCESS0 1210241314898375

i need to grep for all the records having column nos 106,107,108 as 255

can any one help me out

Use cut, then grep

awk '$5==255 || $5==106 || $5==107 || $5==108 {print $0}' filename

Thanks
penchal

awk ' 
          $5 ~ /^10[6-8]/  { print $0 ; next }
          $5 ~ /^255/ { print $0 ; next }'

hi penchal,

great ...u hav given me the way to find the answer. If u dont mind can u explain whatever u hav given

Hi,

awk splits the input lines into fields with space as delimiter.

For your first line of file,

$1=RTMS_LOCATION_CDR
$2=PERIODIC_LOCATION_REPORT
.
.
$5=392
..
.
$11=1210241314898375

In awk script, Place a condition on the 5th filed.
If condition is satisfiled print that entire line

Thanks
Penchal

hi ....can u pls explain the command

hi penchal

i think the command awk '$5==255 {print $0}' filename will be good....
i tried and got the output. i couldnt understand the || $5==106 || $5==107 || $5==108 that u have used in ur response.
anyway thanks ...can i get ur mail id so that i can mail u in case of some other requirement...

Hi

In the first thread, u wrote your requirement as

i need to grep for all the records having column nos 106,107,108 as 255

Thats why i included all those conditions.

Thanks
Penchal

hi,

Thanks for the info.
Now my need is to grep for that pattern in a folder containing many such files.

say for example am having a folder named aemu. under this folder there are so many files (similar to the one i have given already)
i want to grep for 255(in the earlier case) in all the files under that folder

will awk '$5=255 {print $0}' foldername work?

goto aemu folder and run following command

ls | xargs awk '$5==255 {print $0}'

Hi,

for awk you can give multiple files as input

If in folder directory, u are having all your files.

step into folder directory , give the following command.

awk '$5==255 {print $0}' *

or u can stay in parent dirctory of folder and give the command.

awk '$5==255 {print $0}' folder/*

Thanks
Penchal

thanks ...hav u seen my telnet in batchfile thread