gawk—Pattern scanning and processing language

gawk [ POSIX or GNU style options ] –f program-file [ –– ] file …
gawk [ POSIX or GNU style options ] [ –– ] program-text file …

gawk is the GNU Project’s implementation of the awk programming language. It conforms to the definition of the language in the 1003.2 Command Language and Utilities Standard. This version in turn is based on the description in The AWK Programming Language, by Aho, Kernighan, and Weinberger, with the additional features defined in the System V Release 4 version of awk. gawk also provides some GNU-specific extensions.

The command line consists of options to gawk itself, the awk program text (if not supplied via the –f or ––file options), and values to be made available in the ARGC and ARGV predefined awk variables.

gawk options may be either the traditional one-letter options, or the GNU-style long options. Traditional style options start with a single –, while GNU long options start with ––. GNU-style long options are provided for both GNU-specific features and for mandated features. Other implementations of the awk language are likely to only accept the traditional one-letter options.

Following the standard, gawk-specific options are supplied via arguments to the –W option. Multiple –W options may be supplied, or multiple arguments may be supplied together if they are separated by commas, or enclosed in quotes and separated by whitespace. Case is ignored in arguments to the –W option. Each –W option has a corresponding GNU-style long option, as detailed below. Arguments to GNU-style long options are either joined with the option by an = sign, with no intervening spaces, or they may be provided in the next command-line argument.

gawk accepts the following options:

Options Description
–F fs, ––field-separator=fs Use fs for the input field separator (the value of the FS-predefined variable).
–v var=val, ––assign=var=val Assign the value val, to the variable var, before execution of the program begins. Such variable values are available to the BEGIN block of an awk program.
–f program-file, ––file=program-file Read the awk program source from the file program-file, instead of from the first command-line argument. Multiple –f (or ––file) options may be used.
–mf=NNN, –mr=NNN Set various memory limits to the value NNN. The f flag sets the maximum number of fields, and the r flag sets the maximum record size. These two flags and the –m option are from the AT&T Bell Labs research version of awk. They are ignored by gawk, since gawk has no predefined limits.
–W compat, ––compat Run in compatibility mode. In compatibility mode, gawk behaves identically to awk; none of the GNU-specific extensions are recognized. See “GNU Extensions,” later in this manual page, for more information.
–W copyleft, –W copyright, ––copyleft, ––copyright Print the short version of the GNU copyright information message on the error output.
W help, –W usage, ––help, ––usage Print a relatively short summary of the available options on the error output. Per the GNU Coding Standards, these options cause an immediate, successful exit.
–W lint, ––lint Provide warnings about constructs that are dubious or nonportable to other awk implementations.
–W posix, ––posix This turns on compatibility mode, with the following additional restrictions:\x escape sequences are not recognized.
The synonym func for the keyword function is not recognized.
The operators ** and **= cannot be used in place of ˆ and ˆ=.
–W source=program-text, ––source=program-text Use program-text as awk program source code. This option allows the easy intermixing of library functions (used via the –f and ––file options) with source code entered on the command line. It is intended primarily for medium to large awk programs used in shell scripts.
The –W source= form of this option uses the rest of the command-line argument for program-text; no other options to –W will be recognized in the same argument.
–W version, ––version Print version information for this particular copy of gawk on the error output. This is useful mainly for knowing if the current copy of gawk on your system is up-to-date with respect to whatever the Free Software Foundation is distributing. Per the GNU Coding Standards, these options cause an immediate, successful exit.
–– Signal the end of options. This is useful to allow further arguments to the awk program itself to start with a –. This is mainly for consistency with the argument-parsing convention used by most other programs.

In compatibility mode, any other options are flagged as illegal, but are otherwise ignored. In normal operation, as long as program text has been supplied, unknown options are passed on to the awk program in the ARGV array for processing. This is particularly useful for running awk programs via the #! executable interpreter mechanism.

If You Like What We Do Here On LinuxConcept, You Should Consider:

Stay Connected to: Twitter | Facebook

Subscribe to our email updates: Sign Up Now


We are thankful for your support.

Follow me