Why does
echo foo bar..baz bork | awk \'BEGIN{RS=\"..\"} {gsub(OFS,\"\\t\");}1\'
seem to do the same thing as
echo foo bar..baz
If you remember, awk
is a language which has a series of {print $0}
(aka {print}
). The 'pattern' might be a simple regex match, or some other more complicated and general condition, which must evaluate to true if the action is to be executed (as noted by Ed Morton in his comment).
In your example, the 1
is a pattern; it evaluates to true. The action is not specified, so the default action is invoked, which is {print}
or {print $0}
. Any value other than zero or an empty string evaluates to true and will invoke the print. (Note that if you mention an uninitialized variable (for example, c
), then it is autocreated and set to zero and therefore evaluates to false. Hence awk 'c' <<<"Hi"
prints nothing.)
The actions associated with the BEGIN and END patterns are handled specially, of course.