| 1 |
.ds PX \s-1POSIX\s+1 |
| 2 |
.ds UX \s-1UNIX\s+1 |
| 3 |
.ds AN \s-1ANSI\s+1 |
| 4 |
.TH GAWK 1 "May 28 1991" "Free Software Foundation" "Utility Commands" |
| 5 |
.SH NAME |
| 6 |
gawk \- pattern scanning and processing language |
| 7 |
.SH SYNOPSIS |
| 8 |
.B gawk |
| 9 |
[ |
| 10 |
.B \-W |
| 11 |
.I gawk-options |
| 12 |
] [ |
| 13 |
.BI \-F\^ fs |
| 14 |
] [ |
| 15 |
.B \-v |
| 16 |
.IR var = val |
| 17 |
] |
| 18 |
.B \-f |
| 19 |
.I program-file |
| 20 |
[ |
| 21 |
.B \-\^\- |
| 22 |
] file .\^.\^. |
| 23 |
.br |
| 24 |
.B gawk |
| 25 |
[ |
| 26 |
.B \-W |
| 27 |
.I gawk-options |
| 28 |
] [ |
| 29 |
.BI \-F\^ fs |
| 30 |
] [ |
| 31 |
.B \-v |
| 32 |
.IR var = val |
| 33 |
] [ |
| 34 |
.B \-\^\- |
| 35 |
] |
| 36 |
.I program-text |
| 37 |
file .\^.\^. |
| 38 |
.SH DESCRIPTION |
| 39 |
.I Gawk |
| 40 |
is the GNU Project's implementation of the AWK programming language. |
| 41 |
It conforms to the definition of the language in |
| 42 |
the \*(PX 1003.2 Command Language And Utilities Standard |
| 43 |
(draft 11). |
| 44 |
This version in turn is based on the description in |
| 45 |
.IR "The AWK Programming Language" , |
| 46 |
by Aho, Kernighan, and Weinberger, |
| 47 |
with the additional features defined in the System V Release 4 version |
| 48 |
of \*(UX |
| 49 |
.IR awk . |
| 50 |
.I Gawk |
| 51 |
also provides some GNU-specific extensions. |
| 52 |
.PP |
| 53 |
The command line consists of options to |
| 54 |
.I gawk |
| 55 |
itself, the AWK program text (if not supplied via the |
| 56 |
.B \-f |
| 57 |
option), and values to be made |
| 58 |
available in the |
| 59 |
.B ARGC |
| 60 |
and |
| 61 |
.B ARGV |
| 62 |
pre-defined AWK variables. |
| 63 |
.SH OPTIONS |
| 64 |
.PP |
| 65 |
.I Gawk |
| 66 |
accepts the following options, which should be available on any implementation |
| 67 |
of the AWK language. |
| 68 |
.TP |
| 69 |
.BI \-F fs |
| 70 |
Use |
| 71 |
.I fs |
| 72 |
for the input field separator (the value of the |
| 73 |
.B FS |
| 74 |
predefined |
| 75 |
variable). |
| 76 |
.TP |
| 77 |
\fB\-v\fI var\fR\^=\^\fIval\fR |
| 78 |
Assign the value |
| 79 |
.IR val , |
| 80 |
to the variable |
| 81 |
.IR var , |
| 82 |
before execution of the program begins. |
| 83 |
Such variable values are available to the |
| 84 |
.B BEGIN |
| 85 |
block of an AWK program. |
| 86 |
.TP |
| 87 |
.BI \-f " program-file" |
| 88 |
Read the AWK program source from the file |
| 89 |
.IR program-file , |
| 90 |
instead of from the first command line argument. |
| 91 |
Multiple |
| 92 |
.B \-f |
| 93 |
options may be used. |
| 94 |
.TP |
| 95 |
.B \-\^\- |
| 96 |
Signal the end of options. This is useful to allow further arguments to the |
| 97 |
AWK program itself to start with a ``\-''. |
| 98 |
This is mainly for consistency with the argument parsing convention used |
| 99 |
by most other \*(PX programs. |
| 100 |
.PP |
| 101 |
Following the \*(PX standard, |
| 102 |
.IR gawk -specific |
| 103 |
options are supplied via arguments to the |
| 104 |
.B \-W |
| 105 |
option. Multiple |
| 106 |
.B \-W |
| 107 |
options may be supplied, or multiple arguments may be supplied together |
| 108 |
if they are separated by commas, or enclosed in quotes and separated |
| 109 |
by white space. |
| 110 |
Case is ignored in arguments to the |
| 111 |
.B \-W |
| 112 |
option. |
| 113 |
.PP |
| 114 |
The |
| 115 |
.B \-W |
| 116 |
option accepts the following arguments: |
| 117 |
.TP \w'\fBcopyright\fR'u+1n |
| 118 |
.B compat |
| 119 |
Run in |
| 120 |
.I compatibility |
| 121 |
mode. In compatibility mode, |
| 122 |
.I gawk |
| 123 |
behaves identically to \*(UX |
| 124 |
.IR awk ; |
| 125 |
none of the GNU-specific extensions are recognized. |
| 126 |
.TP |
| 127 |
.PD 0 |
| 128 |
.B copyleft |
| 129 |
.TP |
| 130 |
.PD |
| 131 |
.B copyright |
| 132 |
Print the short version of the GNU copyright information message on |
| 133 |
the error output. |
| 134 |
.TP |
| 135 |
.B lint |
| 136 |
Provide warnings about constructs that are |
| 137 |
dubious or non-portable to other AWK implementations. |
| 138 |
.TP |
| 139 |
.B posix |
| 140 |
This turns on |
| 141 |
.I compatibility |
| 142 |
mode, with the following additional restrictions: |
| 143 |
.RS |
| 144 |
.TP \w'\(bu'u+1n |
| 145 |
\(bu |
| 146 |
.B \ex |
| 147 |
escape sequences are not recognized. |
| 148 |
.TP |
| 149 |
\(bu |
| 150 |
The synonym |
| 151 |
.B func |
| 152 |
for the keyword |
| 153 |
.B function |
| 154 |
is not recognized. |
| 155 |
.TP |
| 156 |
\(bu |
| 157 |
The operators |
| 158 |
.B ** |
| 159 |
and |
| 160 |
.B **= |
| 161 |
cannot be used in place of |
| 162 |
.B ^ |
| 163 |
and |
| 164 |
.BR ^= . |
| 165 |
.RE |
| 166 |
.TP |
| 167 |
.B version |
| 168 |
Print version information for this particular copy of |
| 169 |
.I gawk |
| 170 |
on the error output. |
| 171 |
This is useful mainly for knowing if the current copy of |
| 172 |
.I gawk |
| 173 |
on your system |
| 174 |
is up to date with respect to whatever the Free Software Foundation |
| 175 |
is distributing. |
| 176 |
.PP |
| 177 |
Any other options are flagged as illegal, but are otherwise ignored. |
| 178 |
.SH AWK PROGRAM EXECUTION |
| 179 |
.PP |
| 180 |
An AWK program consists of a sequence of pattern-action statements |
| 181 |
and optional function definitions. |
| 182 |
.RS |
| 183 |
.PP |
| 184 |
\fIpattern\fB { \fIaction statements\fB }\fR |
| 185 |
.br |
| 186 |
\fBfunction \fIname\fB(\fIparameter list\fB) { \fIstatements\fB }\fR |
| 187 |
.RE |
| 188 |
.PP |
| 189 |
.I Gawk |
| 190 |
first reads the program source from the |
| 191 |
.IR program-file (s) |
| 192 |
if specified, or from the first non-option argument on the command line. |
| 193 |
The |
| 194 |
.B \-f |
| 195 |
option may be used multiple times on the command line. |
| 196 |
.I Gawk |
| 197 |
will read the program text as if all the |
| 198 |
.IR program-file s |
| 199 |
had been concatenated together. This is useful for building libraries |
| 200 |
of AWK functions, without having to include them in each new AWK |