AWK is an interpreted programming language designed for text processing and typically used as a data extraction and reporting tool.
Elevate your AWK skills through 93 curated exercises across 3 core concepts. Master problem-solving with a structured learning path designed for modern developers.
awk is an interpreted programming language designed for text processing and typically used as a data extraction and reporting tool.
It is a standard feature of most Unix-like operating systems, and has a POSIX specification.
An awk programming paradigm can be said to be "data driven":
an awk program reads lines (or other units of text), and looks for matches of patterns.
When a match occurs, the specified action is performed.
An awk program looks something like
pattern1 {action1}
pattern2 {action2}
...
The pattern can be a regular expression or some other expression that evaluates to a true/false value. The pattern can be omitted, in which case the action is performed for each record of text. The action can be omitted, in which case the default action is to print the current record.
awk is an excellent addition to the user's toolbox.
It is very good at short "one-liner" programs entered at the command line.
A single awk program can replace most pipelines of grep, sed, tr, cut
awk was invented in 1977 by authors Alfred Aho, Peter Weinberger, and Brian Kernighan (whose surnames give us the language's name).
This implementation has come to be known as "old awk".
In 1985, an improved version was released, and is known as "BWK awk" or "new awk" or "the one-true-awk".
This is the version shipped with macOS and some of the *BSD distributions
Another common implementation is mawk, which is based on a bytecode interpreter.
mawk is very fast.
mawk is the default /usr/bin/awk shipped on many Linux distros.
This track will use gawk, GNU's awk implementation.
gawk may not have the raw speed of mawk, but it is very feature-packed, well documented, and has some handy command-line options.
Depending on the platform, awk scripts can be executed by adding a shebang line to the top of the file. On most systems, one of the following two shebangs ought to work. However, since there is no one shebang which works for all systems, we have choosen to omit shebangs.
#!/usr/bin/env -S gawk -f
#!/usr/bin/gawk -f
General purpose
AWK is a venerable, powerful, elegant, and simple tool that everyone should know.
Easy
Extracting a column from your CSV is as simple as "awk -F, '{print $1}' file"
Powerful
Replace complex grep|sed|tr|cut pipelines with a short AWK script.
Do more with less
Simple and flexible data structures, user-defined functions; AWK can do more than you think.
One-liners
With just a few dozen characters, you can achieve impressive text transformations.
Widely used
Besides /bin/sh, AWK is the only other scripting language in the standard Unix environment.
General purpose
AWK is a venerable, powerful, elegant, and simple tool that everyone should know.
Easy
Extracting a column from your CSV is as simple as "awk -F, '{print $1}' file"
Powerful
Replace complex grep|sed|tr|cut pipelines with a short AWK script.
Do more with less
Simple and flexible data structures, user-defined functions; AWK can do more than you think.
One-liners
With just a few dozen characters, you can achieve impressive text transformations.
Widely used
Besides /bin/sh, AWK is the only other scripting language in the standard Unix environment.