Conceptual Overview

awk is a pattern-matching program for processing files, especially when each line has a simple field-oriented layout. Linux provides the GNU version of awk, called gawk, which provides a number of additional features. This utility can be invoked either through the standard name awk or through gawk.

This chapter describes functionality that is found in gawk. Most of this discussion applies to all versions of awk, but items marked “gawk-specific” or as an “extension” may not apply to versions of awk other than GNU’s. If portability to older, non-Linux systems is important, do not use gawk-specific features.

With gawk, you can:

  • Think of a text file as made up of records and fields in a textual database.

  • Perform arithmetic and string operations.

  • Use programming constructs, such as loops and conditionals.

  • Produce formatted reports.

  • Define your own functions.

  • Execute Unix commands from a script.

  • Process the results of Unix commands.

  • Process command-line arguments gracefully.

  • Work easily with multiple input streams.

  • Flush open output files and pipes.

  • Sort arrays.

  • Retrieve and format system time values.

  • Do bit manipulation.

  • Internationalize your gawk programs, allowing strings to be translated into a local language at runtime.

  • Perform two-way I/O to a coprocess.

  • Open a two-way TCP/IP connection to a socket.

  • Dynamically add built-in functions.

  • Profile your gawk programs.

Get Linux in a Nutshell, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.