Reputation: 1817
I have a function that searches one column for one string, how would I allow it so I can provide my script with multiple columns to search with multiple search strings?
awk -v s=$1 -v c=$2 '$c ~ s { print $0 }' $3
Thanks
Upvotes: 1
Views: 222
Reputation: 212208
You can use an or clause in the pattern:
awk -v s=$1 -v c=$2 '$c ~ s || $3 == "foo"' $3
will print all lines in the file $3 in which column $2 matches the string $1 or $3 matches the string "foo". Note that the action "print $0" is redundant, and is the default if no action is given.
Upvotes: 1