UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 10.5 Alphabetical Summary of sed CommandsChapter 11Next: 11.2 Command-Line Syntax
 

11. The awk Programming Language

Contents:
Conceptual Overview
Command-Line Syntax
Patterns and Procedures
Built-in Variables
Operators
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.[1] Every modern Unix system comes with a version of new awk, and its use is recommended over old awk.

[1] 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: http://cm.bell-labs.com/~bwk. Michael Brennan's mawk is available via anonymous FTP from ftp://ftp.whidbey.net/pub/brennan/mawk1.3.3.tar.gz. Finally, the Free Software Foundation has a version of awk called gawk, available from ftp://gnudist.gnu.org/gnu/gawk/gawk-3.0.4.tar.gz. 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:


Previous: 10.5 Alphabetical Summary of sed CommandsUNIX in a Nutshell: System V EditionNext: 11.2 Command-Line Syntax
10.5 Alphabetical Summary of sed CommandsBook Index11.2 Command-Line Syntax

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System