The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-05-2008
simha77777 simha77777 is offline
Registered User
 

Join Date: Jul 2006
Posts: 8
Awk - select from a list

Hi all,

I am trying to select some columns from a file, based on the list of values.
Would like to know how best I can achive this.

If coulmn 1 has a value of 57 then print the ist column (This works)
Code:
awk -F'  ' '{if ( $1 == 57 ) {print $1}}' file.txt
Now my requirement is that I have to check the column with multiple values. (If I have 2 use an OR operator as below)
Code:
awk -F'  ' '{if ( $1 == 57 || $1 == 58) {print $1}}' file.txt
I have 100 values which I need to check with the first column. Is there a way to do this, without writing in 100 conditions in the if statement?
(I could put the 100 values into a file if that makes things easier)

Please let me know if you need more information. Any help greatly appreciated.
Reply With Quote
Forum Sponsor