Ste Prescott
Ste Prescott

Reputation: 1817

Awk getting results back with multiple columns

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

Answers (1)

William Pursell
William Pursell

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

Related Questions