A Practical Guide to Understanding AWK

Over at the Developers Area, Liran B.H has a nice practical guide to understanding AWK. There’s a whole book dedicated to AWK so obviously a single blog post isn’t going to cover everything but it does speak to one of AWK’s most powerful features: the one-liner. Brian Kernighan—the ‘K’ in AWK—has said that AWK excells in 1, 2, or 3 line programs and is hard to beat in that domain.

Liran B.H’s guide focuses on short programs for manipulating text data and shows a small amount of the power that AWK has. Two of my favorite features of AWK are the implicit main loop that reads each line of the text and operates on it usually as the result of matching some regex. The other part I like is that all arrays are associative arrays and you don’t have to worry about what form an array index takes or even keep their type consistent. You use whatever’s handiest and it just works. These days, of course, most “modern” languages have associative arrays built in (although maybe not by that name) but when AWK was first implemented, that was much less true.

The post doesn’t cover arrays but does a good job on the implicit main loop and using regexes to trigger actions. AWK is a nice language for certain types of problems and well worth knowing. Take a look at the post and if you want more, find a copy of the AWK book or check out more comprehensive guides such as this one over at Grymoire.com.

This entry was posted in General and tagged . Bookmark the permalink.