View Single Post
  #1 (permalink)  
Old September 23rd, 2008, 08:33 AM
elygp elygp is offline
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

Reply With Quote