Book HomeBook TitleSearch this book

Chapter 11. The awk Programming Language


Conceptual Overview
Command-Line Syntax
Patterns and Procedures
Built-in Variables
Variables and Array Assignments
User-Defined Functions
Group Listing of awk Functions and Commands
Implementation Limits
Alphabetical Summary of Functions and Commands

This chapter presents the following topics:

For more information, see sed & awk, listed in the Bibliography.

11.1. Conceptual Overview

awk is a pattern-matching program for processing files, especially when they are databases. The new version of awk, called nawk, provides additional capabilities.[10] Every modern Unix system comes with a version of new awk, and its use is recommended over old awk.

[10]It really isn't so new. The additional features were added in 1984, and it was first shipped with System V Release 3.1 in 1987. Nevertheless, the name was never changed on most systems.

Different systems vary in what the two versions are called. Some have oawk and awk, for the old and new versions, respectively. Others have awk and nawk. Still others only have awk, which is the new version. This example shows what happens if your awk is the old one:

$ awk 1 /dev/null
awk: syntax error near line 1
awk: bailing out near line 1

awk exits silently if it is the new version.

Source code for the latest version of awk, from Bell Labs, can be downloaded starting at Brian Kernighan's home page: Michael Brennan's mawk is available via anonymous FTP from Finally, the Free Software Foundation has a version of awk called gawk, available from All three programs implement “new” awk. Thus, references below such as “nawk only,” apply to all three. gawk has additional features.

With original awk, you can:

With nawk, you can also:

In addition, with GNU awk (gawk), you can:

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.