"grep string | grep string" with awk without pipe

The default action with awk is to print, so the equivalent of

output | grep string1 | grep string2

is

output | awk '/string1/ && /string2/'

e.g.

$ cat tst
foo
bar
foobar
barfoo
foothisbarbaz
otherstuff

$ cat tst | awk '/foo/ && /bar/'
foobar
barfoo
foothisbarbaz

If you want awk to find lines that match both string1 and string2, in any order, use &&:

 output | awk '/string1/ && /string2/ {print $XY}'

If you want to match either string1 or string2 (or both), use ||:

 output | awk '/string1/ || /string2/ {print $XY}'

Tags:

Bash

Awk