Linux in a Nutshell, Third Edition
by Ellen Siever, Stephen Spainhour, Jessica P. Hekman, Stephen Figgins
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. Normally you should be able to invoke this utility using either awk or gawk on the shell command line.
This chapter presents the following topics:
Conceptual overview
Command-line syntax
Patterns and procedures
System variables
Operators
Variable and array assignment
Group listing of commands
Alphabetical summary of commands
For more information, see the O’Reilly book sed & awk, 2d ed., by Dale Dougherty and Arnold Robbins.
Conceptual Overview
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 the database.
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.
Process command-line arguments more gracefully.
Produce formatted reports.
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.
Read now
Unlock full access