01. Introduciton to AWK

AWK is a powerful but simple scripting language designed for text extraction and processing. Due to its versatility and simple usage, it is a widely-used tool, and there are entire books written on it.

Why use AWK?

Although it's possible to translate any AWK script into C for faster processing, AWK is often easier to write and debug. Thus, even though a C program may execute faster, it's preferrable to use AWK due to its simplicity and ease of use.

Origins of the name

The name AWK comes from its authors Alfred Aho, Peter Weinberger and Brian Kernighan, who developed it in Bell Labs in the 1970's. AWK also serves as a homonym of its mascot, the auk bird.

The auk bird.
The auk bird, which was also on the cover of the first AWK manual.

AWK features

AWK provides command line users with a variety of functions. You may use a single AWK script to process several files within a pipeline or apply the commands to several files at once. Here are just a few of the features that AWK provides:

  • Text formatting
  • Formatted text outputs
  • Perform mathematical and string operations
  • Field extraction and rearrangement

In short, AWK can be of immense help to anything that has to do with text processing or data-table manipulation.

Variations of AWK

There have been a variety of AWK implementations as users started expanding on the language.

Original awk.
New and improved awk. Used by OS X.
GNU awk. Mostly ships with Linux distributions.
Very fast AWK implementation based on bytecode interpreter.

Installing gawk

For this tutorial, we'll be sticking to gawk, which is the GNU version of AWK (GNU is simply a suite of open-source utilities - learn about the history of UNIX and GNU). To install gawk on a Debian-based Linux platform, use the apt-get package manager.

$ sudo apt-get update
$ sudo apt-get install gawk

For RPM based Linux, use yum.

$ sudo yum install gawk

For Mac OS X platform, use homebrew, the package manager for OS X.

$ brew install gawk

Commenting in AWK

One last thing to mention before moving on - to comment in AWK, use either the hashtag symbol (#) or two forward slashes (//).

Notes before getting started

AWK is a difficult programming language to learn, as most of its concepts, syntax and notations are intertwined with each other. Thus, learning one piece of AWK involves having to know some other parts. Due to this, some of the lessons in this tutorial may introduce concepts that will be covered in more detail in a future lesson. So if you see something new and not explained in detail, try your best to understand it and sit tight until we cover it more formally later. Now let's get started!

Aching back from coding all day?

Foam Seat Cushion

Aching back from coding all day? Try Back Problems

This foam seat cushion relieves lowerback pain, numbness and pressure sores by promoting healthy weight distribution, posture and spine alignment. Furthermore, it reduces pressure on the tailbone and hip bones while sitting. Perfect for sitting on the computer desk for long periods of time.

$ Check price
99.9599.95Amazon 4.5 logo(9,445+ reviews)

More Back Problems resources

Take your Linux skills to the next level!

Linux for Beginners

Take your Linux skills to the next level! Try Linux & UNIX

Linux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand.

$ Check price
24.9924.99Amazon 4.5 logo(101+ reviews)

More Linux & UNIX resources