How to understand the following awk command?
nawk 'a-- >= 0; /datamart_extractrelations_static/ {a = 30}' app.log
Given a awk program has a format of:
pattern { action }
What is 'a-- >= 0' do? when does this operation get executed?
The command is the same as:
nawk 'a-- >= 0 {print}; /datamart_extractrelations_static/ {a = 30}' app.log
If a-- >= 0
awk
will print the current line since print
is the default action in awk
which will be executed if no action was specified.
As a result, the command will print the 30ths line after a line that contains the pattern datamart_extractrelations_static
To better understand this, you can simply try the following command:
awk '1' input
Since 1
will always evaluate to true
and the default action is print
awk
prints every line of input unchanged.