
Command-Line Syntax | 771
gawk
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Standard Options
The standard options are:
-Ffs
Set the field separator to fs. This is the same as setting the built-in variable
FS. gawk allows fs to be a regular expression. Each input line, or record,is
divided into fields by whitespace (spaces or tabs) or by some other user-defin-
able field separator. Fields are referred to by the variables $1, $2,…, $n. $0
refers to the entire record.
-v var=value
Assign a value to variable var. This allows assignment before the script begins
execution.
For example, to print the first three (colon-separated) fields of each record on
separate lines:
awk -F: '{ print $1; print $2; print $3 }' /etc/passwd
Numerous examples are shown later in “Simple Pattern-Procedure Examples.”
Important gawk Options
Besides the standard command line options, gawk has a large number of addi-
tional options. This section lists those of most value in day-to-day use. Any
unique abbreviation of these options is acceptable.
--dump-variables[=file]
When the program has finished running, print a sorted list of global vari-
ables, their types, and their final values to file. The default file is awkvars.out.
--gen-po
Read the awk program and print all strings marked as translatable to stan-
dard output in the form of a GNU gettext Portable Object file. ...