Filter records in a file with sed or awk (UNIX)
Hi all,
I would like to extract records of a file based on a condition. The file contains 47 columns, and I would like to extract only those records that match a certain value in one of the columns, e.g.
COL1 COL2 COL3 ............... COL47
1 XX 45 N
2 YY 34 y
3 ZZ 44 N
4 XX 89 Y
5 XX 45 N
6 YY 84 D
7 ZZ 22 S
From this file, I would like to extract all records whose COL2=XX or YY, and all other records will be excluded (as shown below).
COL1 COL2 COL3 ............... COL47
1 XX 45 N
2 YY 34 y
4 XX 89 Y
5 XX 45 N
6 YY 84 D
Does anybody know how to do this using sed or awk or any other UNIX tool? Thank you.
|