AWK Examples

Before Perl and other such scripting languages, there was AWK. AWK is a great language for doing text manipulation chores. It has regular expressions, associative arrays, automatic splitting of input lines into fields, and other features to make working with text easy. The traditional reference for the language is The AWK Programming Language. It’s out of print now but you can still get a copy if you don’t mind spending an exorbitant amount. There are, of course, PDF copies available but I have no idea of their legal status.

Even if you can’t get a copy of the book, there’s the excellent The GNU Awk User’s Guide that serves as a reference manual for the GNU’s AWK implementation. If you’re looking for a quick go-by or set of recipes, Sundeep Agarwal has a nice set of AWK examples. The examples make it easy to get going and use AWK in your everyday work.

AWK excels in “one-liners” and is therefore often used in pipelines. It can also be used to build larger programs. Before Org mode, I used an AWK program to take a list of tasks and the times spent on them to typeset a time sheet with Groff. I still prefer it to Perl for most jobs that I can’t do with Org mode and Emacs. If you’re looking for a quick and easy introduction to AWK, take a look at Agarwal’s examples.

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