Skip to Main Content
Linux in a Nutshell, Fourth Edition
book

Linux in a Nutshell, Fourth Edition

by Ellen Siever, Stephen Figgins, Aaron Weber
June 2003
Beginner to intermediate content levelBeginner to intermediate
944 pages
43h 1m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, Fourth Edition

Chapter 13. The gawk Scripting Language

gawk is the GNU version of awk , a powerful pattern-matching program for processing text files that may be composed of fixed- or variable-length records separated by some delineator (by default, a newline character). gawk may be used from the command line or in gawk scripts. You should normally be able to invoke this utility using either awk or gawk on the shell command line.

With gawk, you can:

  • Conveniently process a text file as though it were made up of records and fields in a textual database.

  • Use variables to change those records and fields.

  • Execute shell commands from a script.

  • Perform arithmetic and string operations.

  • Use programming constructs such as loops and conditionals.

  • Define your own functions.

  • Process the result of shell commands.

  • Produce formatted reports.

For more information on gawk, see sed & awk (O’Reilly) or Effective gawk Programming (O’Reilly).

Command-Line Syntax

gawk ’s syntax has two forms:

            gawk [options] 'script' var=value file(s)
            gawk [options] -f 
            scriptfile var=value file(s)

You can specify a script directly on the command line, or you can store a script in a scriptfile and specify it with -f. Multiple -f options are allowed; awk concatenates the files. This feature is useful for including libraries.

gawk operates on one or more input files. If none are specified (or if - is specified), gawk reads from standard input.

Variables can be assigned a value on the command line. The value assigned to a variable can be a literal, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux in a Nutshell, 6th Edition

Linux in a Nutshell, 6th Edition

Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
Linux in Action

Linux in Action

David Clinton
Hands-On System Programming with Linux

Hands-On System Programming with Linux

Kaiwan N. Billimoria, Tigran Aivazian
Embedded Linux for Developers

Embedded Linux for Developers

Alexandru Vaduva, Alex González, Chris Simmonds

Publisher Resources

ISBN: 0596004826