Better way to do it ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Better way to do it ?
# 1  
Old 07-30-2015
Better way to do it ?

Hi All,
I have a file with 70 columns which is pipe delimited. I need to search certain values in column 13 and print the record line if it matches.

The following command works, but I think there should be a better way to do this.
Any inputs will be appreciated.

Code:
awk -F "|" '$13=="190" || $13=="191" || $13=="099" || $13=="192" || $13=="193" || $13=="198" || $13=="199" || $13=="298" || $13=="800" {print $0}' $filename > av01

# 2  
Old 07-30-2015
Code:
awk '
  BEGIN {
     FS=OFS="|"
     split("190|192|099|192|193|198|199|298|800",t,FS)
     for(i=1; i in t;i++) a[t[i]]
  }
  $13 in a' myFile

# 3  
Old 07-30-2015
Or try a regular expression, for example:
Code:
awk -F "|" '$13~/^(099|19[0-3,8-9]|298|800)$/' "$filename" > av01



--
instead of 19[0-3,8-9] you can also use 190|191|192|193|198|199
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question