How I program in AWK

43 points by xonix


susam

After running into several incompatibility issues on Solaris and AIX systems about a decade ago while using sed and awk, I learnt to stick to the POSIX-specified feature set as much as possible. I always keep a link to the POSIX specification bookmarked so I can quickly look up command-line options, regular expression syntax and the sed and awk specifications. An updated POSIX specification was published in 2024 and is available here: https://pubs.opengroup.org/onlinepubs/9799919799/.

The pages I find myself going back to over and over again are:

  1. Shell Command Language
  2. Regular Expressions
  3. Utilities
  4. sed
  5. awk

The nice thing about the second link is that it documents both Basic Regular Expression (BRE) and Extended Regular Expression (ERE) on a single page, which is convenient while switching between grep and grep -E or sed and sed -E. Fortunately, awk uses ERE by default.

petecorey

Reminds me of the beautiful things @thingskatedid used to post on Twitter back in the day. https://x.com/thingskatedid/status/1286559756967002113

ndegruchy

I'm always impressed with folks who write programs in AWK. I know there are several variations of inconsistent popularity. GAWK is what I'm familiar with, and what I imagine most people get when they type awk into the terminal. Are there any advantages to the non-GNU AWK's?

I really need to find my copy of the awk book and re-read it...

dfawcus

I would certainly write small scripts in AWK, especially as a way of consolidating certain poorly conceived shell scripts. It is quite useful, but a bit idiosyncratic.

The limiting factor is when one needs structures, at which point it quickly becomes unwieldy, and another language is often a better choice. These days, my 'other' language will often be Go, as it is quite quick to turnaround in a script-like fashion.