The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 11-14-2008
CarlosNC CarlosNC is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is:

Code:
awk -v TYP="$1 $2 $3 $4 $5 $6" '
  BEGIN {
       CTYP = split (TYP,TYPP," ")
  }
   {for ( i=1; i <= CTYP; i++ ) {
           if ($0 ~ TYPP[i]) {print; break}
      }}
 ' file1 > file2
exit 0
This works, but is not efficient at all.
Could someone suggested an alternate method to handle this scenario? Any help is appreciated.

Thank you.