alencc1986
alencc1986

Reputation: 95

Searching for multiple strings in AWK

How are you?

I know it's possible to use: awk '/string/ { print }' filename. Is there any thing which allows me to use the same command + multiple strings? Maybe: awk '/string1/ /string2/ ... { print }' filename?

Thanks in advance.

Upvotes: 1

Views: 5633

Answers (1)

MarcoLucidi
MarcoLucidi

Reputation: 2197

yes there are of course lot of ways to accomplish "multi strings match", for example (print is the default action):

$ cat file
string1
string2
string3
string4
$ awk '/string1|string2/' file
string1
string2
$ awk '/string1/ || /string2/' file
string1
string2
$

patterns are really flexible, here some documentation from gawk: https://www.gnu.org/software/gawk/manual/html_node/Pattern-Overview.html

Upvotes: 2

Related Questions