Today I was searching for a command online to print next two lines after a pattern and I came across an awk command which I\'m unable to understand.
$ /usr/x
Wonderfully obscure. Will update when time allows.
_ is being used as a variable name. The && is a logical operator that has 2 true actions run together. Once the value of _ is reduced to zero, the 2nd half of the && is false and no output is generated.
print -- "
xxxxx
yyyy
PATTERN
zzz
aa
bbb
ccc
ffffd" | awk '_&&_--;/PATTERN/{_=2}'
output
zzz
aa
debug version
print -- "
xxxxx
yyyy
PATTERN
zzz
aa
bbb
ccc
ffffd" | awk '_&&_--;{print "_="_;print _&&_};/PATTERN/{_=2;print "_="_ }'
output
_=
0
_=
0
_=
0
_=
0
_=2
zzz
_=1
1
aa
_=0
0
_=0
0
_=0
0
_=0
0