Hacker News new | past | comments | ask | show | jobs | submit login

This is a nice little run through of a real life example.

Once you realise that awk's model is 'match pattern { do actions; }' everything makes a whole lot more sense.




Awk also supports BEGIN and END actions that take place at the start and at the end of execution.

BEGIN might be used to initialise Awk variables or print initial messages, while END can be used to print a summary of actions at the end.

See [1] https://www.grymoire.com/Unix/Awk.html#uh-1


You can also use either BEGIN or END as the only entrypoints, essentially using AWK as you'd use any other programming language. Yes, sometimes this defeats the point of what AWK excels at, but it's good to know.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: