I'm learning AWK these days for text processing. But I'm very much confused about AWK syntax. I read on Wikipedia that the syntax follows this format:
(conditions) {actions}
I assumed I can follow the same syntax in a BEGIN and END block. But I'm getting a syntax error when I run the following script.
awk 'BEGIN{}
(1 == 1) {print "hello";}
END{
(1==1) {print "ended"}}' $1
However, if I make a little bit of a change inside the END block and add 'if' before the condition, it runs just fine.
awk 'BEGIN{}
(1 == 1) {print "hello";}
END{
if (1==1) {print "ended"}}' $1
Why is it mandatory to write 'if' in END block while it's not needed in normal blocks?