Get started with AWK
I have recently (re)discovered AWK through using GoAWK, a POSIX-compliant AWK interpreter written in Go, with CSV support — courtesy of Ben Hoyt. This inspired me to (re)acquaint myself with AWK itself…
What is AWK?
AWK is a true GNU/Linux classic, designed by Alfred Aho, Peter Weinberger, and Brian Kernighan — three of the biggest names in UNIX development and computer science in general. It is a convenient and expressive programming language that can be applied to a wide variety of computing and data-manipulation tasks.
Of course this tutorial is only a brief overview of the basics of AWK. There are several more elaborated tutorials to be found online, as well as the original (and delightfully-terse, as Ben Hoyt calls it) manual The AWK Programming Language written by the designers…
Workflow and structure
Starting out, we need to understand the workflow and program structure of AWK.
An AWK program follows this outline:
- execute commands from
BEGIN
block - read a line from input stream
- execute commands on a line or rather ‘record’
- repeat if end of file has not been reached
- execute commands from
END
block