A BEGIN block in awk
is executed only once, before the first input record is read.
An END rule is executed only once, after all the input is read.
In your transformation, since you put everything in BEGIN
block, it becomes a no-op since values of NF
, $1
, $2
.. etc is not even set. Hence you get an empty file. If you remove it it should work fine.
BEGIN
and END
blocks are not mandatory so you don't have to keep them in your awk
script. BEGIN
is often used to print titles, headers, initializing variables to particular values etc. END
block is often used to do final processing after entire input is read.