
774
|
Chapter 11: The gawk Programming Language
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Print lines that contain less than 20 characters:
length($0) < 20
Print each line that begins with Name: and that contains exactly seven fields:
NF = = 7 && /^Name:/
Print the fields of each record in reverse order, one per line:
{
for (i = NF; i >= 1; i--)
print $i
}
Built-in Variables
All awk variables are included in gawk.
Version Variable Description
awk ARGC Number of arguments on the command line.
ARGV An array containing the command-line arguments, indexed from 0 to ARGC - 1.
ENVIRON An associative array of environment variables.
FILENAME Current filename.
FNR Like NR, but relative to the current file.
FS Field separator (a space).
NF Number of fields in current record.
NR Number of the current record.
OFMT Output format for numbers ("%.6g").
OFS Output field separator (a space).
ORS Output record separator (a newline).
RLENGTH Length of the string matched by match() function.
RS Record separator (a newline).
RSTART First position in the string matched by match() function.
SUBSEP Separator character for array subscripts ("\034").
$0 Entire input record.
$
n nth field in current record; fields are separated by FS.
gawk ARGIND Index in ARGV of current input file.
BINMODE Controls binary I/O for input and output files. Use values of 1, 2, or 3 for ...