Example 2
Emulation of wc -w
BEGIN{ w=0 }
{ w+= NF }
END{ print w }
END{ print w }; { w+=NF }; BEGIN{ w=0 }
would work too.
String manipulation
bash$ awk '{ sub(/[^ ]* */,""); print $0 }'
- The content of the variables NF and $n is reassigned.
- It is no more possible to reference substrsings of REs (like \1 in sed)
- gsub() for global substitution