![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| formating number strings | nhatch | UNIX for Dummies Questions & Answers | 10 | 04-28-2009 12:55 AM |
| Parse apart strings of comma separated data with varying number of fields | 2reperry | Shell Programming and Scripting | 7 | 09-12-2008 01:33 PM |
| how to search with 2 strings. | syamkp | Shell Programming and Scripting | 2 | 03-10-2008 04:50 AM |
| Search between strings with an OR | pbsrinivas | Shell Programming and Scripting | 3 | 07-12-2007 04:46 AM |
| Search for strings | lesstjm | UNIX for Dummies Questions & Answers | 5 | 04-26-2002 09:58 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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
Could someone suggested an alternate method to handle this scenario? Any help is appreciated. Thank you. |
|
||||
|
Thanks Jim, that makes sense using grep, but I should have been more clear, it needs to be awk because there is more to my script, but I removed it to simplify my post here. I use awk here because I extract other info related to the hits from the file as well.
|
| Sponsored Links | ||
|
|