AWK is a programming language and command line tool designed for text processing and exists since 1977. The most widely adopted implementations being GNU AWK (gawk) and mawk by Mike Brennan.

The basic structure of an AWK program is a sequence of patterns and coresponding actions.

# comment
/pattern-1/ { actions; }

# comment
/pattern-N/ { actions; }

On execution every record (default line) in a document gets evaluated against the patterns and if a pattern matches it’s actions are executed.

Patterns can be combined form regular and boolean expressions i.e.

/^[0-9]+/ { actions; }
/(WARNING|ERROR|PANIC)/ { actions; }
/debug/ || debug == true { actions; }

Besides the usual boolean operators AWK includes ~ and !~ for matching a string against a regex.

Special patterns like BEGIN and END which are executed on start and stop of a program, are useful for variable initilization or printing a final report.

Since AWK supports a wide range of statements and built-in functions these are just some example actions.

{ print $1; }
{ next; }
{ if (i in items) { actions; } }
{ for (i in items) { actions; } }

The two main data types supported by AWK are numbers and strings which can be seemlessly converted into each other. In case a string can’t be converted it’s value equals 0.

AWK allows to declare variables in an action block using the = operator. By default all variables are assigned to a global namespace. A variables default value is "", the empty string.

Additionaly to primitive variables AWK supports unidimensional associative arrays. These can be started dynamically using arr[key] = val.

To make it easier to work on a records data in an action AWK uses fields. Fields are normaly assigned by spliting a record on each field seperator (default whitespace) and can be accessed using $1...$N. $0 contains the value of the hole line, modifying this variable also changes the lines value for further processing. Different record and field seperators can be configured by modifiying the built-in RS and FS variables.

For more information the following resources can be conducted: