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 input, output, or both kinds of files, respectively. Set it on the command line to affect standard input, standard output, and standard error.

 

ERRNO

A string indicating the error when a redirection fails for getline or if close( ) fails.

 

FIELDWIDTHS

A space-separated list of field widths to use for splitting up the record, instead of FS.

 

IGNORECASE

When true, all regular expression matches, string comparisons, and index( ) ignore case.

 

LINT

Dynamically controls production of “lint” warnings. With a value of “fatal”, lint warnings ...

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.