get lines with multiple values at a position

Hi,

I have a file like below:

ABC,1001,DEFG,40000
AVD,2002,FGRG,3000
DBF,2002,HDGD,3454
GDF,4564,GRTR,5656
GDF,4659,GGTD,10002
....
.....

I have to get all the lines which contains 2002 and 4659 at the second position. Please help.

The output file will be like:

AVD,2002,FGRG,3000
DBF,2002,HDGD,3454
GDF,4659,GGTD,10002

Many Thanks,
D

egrep '^[^,]*,(2002|4659),' file

Or:

awk '$2==4659||$2==2002' FS=',' file

awk -F, '$2=="2002" || $2=="4659" ' file

Or:

awk '$2~/^(2002|4659)$/' FS=, file

thanks guyss ... !!!!

Cheers
D

Hi All,

If i have a similar file with no commas to separate the fields, is there any way:

1001DEFG,40000
2002KGRG,3000
2002HDGD,3454
4564GRTR,5656
4659GGTD,10002

to get :

2002KGRG,3000
2002HDGD,3454
4659GGTD,10002

Where i have to get lines based on the first four digits of each line.

Thanks,
D

egrep '^(2002|4659|more digits here)'

Thanks.. will it be as fast as awk .. as ill be working with huge files

Try it. Read up on regular expressions.