| 1 | .\" AWK Reference Card --- Arnold Robbins, [email protected]
|
|---|
| 2 | .\"
|
|---|
| 3 | .\" Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
|---|
| 4 | .\" 2003, 2004, 2005 Free Software Foundation, Inc.
|
|---|
| 5 | .\"
|
|---|
| 6 | .\" Permission is granted to make and distribute verbatim copies of
|
|---|
| 7 | .\" this reference card provided the copyright notice and this permission
|
|---|
| 8 | .\" notice are preserved on all copies.
|
|---|
| 9 | .\"
|
|---|
| 10 | .\" Permission is granted to process this file through troff and print the
|
|---|
| 11 | .\" results, provided the printed document carries copying permission
|
|---|
| 12 | .\" notice identical to this one except for the removal of this paragraph
|
|---|
| 13 | .\" (this paragraph not being relevant to the printed reference card).
|
|---|
| 14 | .\"
|
|---|
| 15 | .\" Permission is granted to copy and distribute modified versions of this
|
|---|
| 16 | .\" reference card under the conditions for verbatim copying, provided that
|
|---|
| 17 | .\" the entire resulting derived work is distributed under the terms of a
|
|---|
| 18 | .\" permission notice identical to this one.
|
|---|
| 19 | .\"
|
|---|
| 20 | .\" Permission is granted to copy and distribute translations of this
|
|---|
| 21 | .\" reference card into another language, under the above conditions for
|
|---|
| 22 | .\" modified versions, except that this permission notice may be stated in
|
|---|
| 23 | .\" a translation approved by the Foundation.
|
|---|
| 24 | .\"
|
|---|
| 25 | .\" Strings to save typing
|
|---|
| 26 | .ds AK \*(FCawk\*(FR
|
|---|
| 27 | .ds GK \*(FCgawk\*(FR
|
|---|
| 28 | .ds PK \*(FCpgawk\*(FR
|
|---|
| 29 | .ds NK Bell Labs \*(FCawk\*(FR
|
|---|
| 30 | .ds MK \*(FCmawk\*(FR
|
|---|
| 31 | .\"
|
|---|
| 32 | .\"
|
|---|
| 33 | .de TD\" tab defaults
|
|---|
| 34 | .ta .2i .78i 1i 1.2i 1.4i 1.7i
|
|---|
| 35 | ..
|
|---|
| 36 | .de TE
|
|---|
| 37 | .TD
|
|---|
| 38 | ..
|
|---|
| 39 |
|
|---|
| 40 | .sp
|
|---|
| 41 | .ce
|
|---|
| 42 | \*(CD\f(HB\s+8AWK REFERENCE\s0\*(FR
|
|---|
| 43 | .sp
|
|---|
| 44 | .\" --- Table Of Contents
|
|---|
| 45 | .ta 2.4i 2.6iR
|
|---|
| 46 | .lc .
|
|---|
| 47 | .ES
|
|---|
| 48 | .in +.2i
|
|---|
| 49 | .nf
|
|---|
| 50 | \*(FRAction Statements 7
|
|---|
| 51 | Arrays 11
|
|---|
| 52 | Awk Program Execution 4
|
|---|
| 53 | Bit Manipulation Functions (\*(GK) 16
|
|---|
| 54 | Bug Reports 2
|
|---|
| 55 | Closing Redirections 12
|
|---|
| 56 | Command Line Arguments (standard) 2
|
|---|
| 57 | Command Line Arguments (\*(GK) 3
|
|---|
| 58 | Command Line Arguments (\*(MK) 4
|
|---|
| 59 | Conversions And Comparisons 9
|
|---|
| 60 | Copying Permissions 18
|
|---|
| 61 | Definitions 2
|
|---|
| 62 | Dynamic Extensions (\*(GK) 14
|
|---|
| 63 | Environment Variables (\*(GK) 16
|
|---|
| 64 | Escape Sequences 8
|
|---|
| 65 | Expressions 11
|
|---|
| 66 | Fields 6
|
|---|
| 67 | FTP/HTTP Information 18
|
|---|
| 68 | Historical Features (\*(GK) 10
|
|---|
| 69 | Input Control 12
|
|---|
| 70 | Internationalization (\*(GK) 18
|
|---|
| 71 | Lines And Statements 5
|
|---|
| 72 | Localization (\*(GK) 17
|
|---|
| 73 | Numeric Functions 14
|
|---|
| 74 | Output Control 12
|
|---|
| 75 | Pattern Elements 7
|
|---|
| 76 | POSIX Character Classes (\*(GK) 6
|
|---|
| 77 | Printf Formats 13
|
|---|
| 78 | Records 6
|
|---|
| 79 | Regular Expressions 5
|
|---|
| 80 | Signals (\*(PK) 4
|
|---|
| 81 | Special Filenames 14
|
|---|
| 82 | String Functions 15
|
|---|
| 83 | Time Functions (\*(GK) 16
|
|---|
| 84 | User-defined Functions 17
|
|---|
| 85 | Variables 8\*(CX
|
|---|
| 86 | .in -.2i
|
|---|
| 87 | .EB "\s+2\f(HBCONTENTS\*(FR\s0"
|
|---|
| 88 | .sp .4
|
|---|
| 89 | .TD
|
|---|
| 90 | .fi
|
|---|
| 91 | \*(CD\*(FRArnold Robbins wrote this reference card.
|
|---|
| 92 | We thank
|
|---|
| 93 | Brian Kernighan and Michael Brennan who reviewed it.
|
|---|
| 94 | .sp .4
|
|---|
| 95 | .SL
|
|---|
| 96 | .sp .4
|
|---|
| 97 | .so SRCDIR/ad.block
|
|---|
| 98 | .\" a subtlety here; this line changes color. We rely on it
|
|---|
| 99 | .\" also to provide a blank line.
|
|---|
| 100 | \*(CD
|
|---|
| 101 | .SL
|
|---|
| 102 | .nf
|
|---|
| 103 | \*(FRCopyright \(co 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
|
|---|
| 104 | Free Software Foundation, Inc.
|
|---|
| 105 | .nf
|
|---|
| 106 | .BT
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | .\"
|
|---|
| 110 | .\"
|
|---|
| 111 | .\" --- Definitions
|
|---|
| 112 | .fi
|
|---|
| 113 | .ES
|
|---|
| 114 | \*(CDThis card describes POSIX AWK, as well as the three
|
|---|
| 115 | freely available \*(AK implementations
|
|---|
| 116 | (see \fHFTP/HTTP Information\fP below).
|
|---|
| 117 | \*(CLCommon extensions (in two or more versions) are printed in light blue.
|
|---|
| 118 | \*(CBFeatures specific to just one version\(emusually GNU AWK (\*(GK)\(emare
|
|---|
| 119 | printed in dark blue.
|
|---|
| 120 | \*(CRExceptions and deprecated features are printed in red.
|
|---|
| 121 | \*(CDFeatures mandated by POSIX are printed in black.
|
|---|
| 122 | .sp .5
|
|---|
| 123 | Several type faces are used to clarify the meaning:
|
|---|
| 124 | .br
|
|---|
| 125 | .nr IN \w'\(bu '
|
|---|
| 126 | \(bu \*(FC\*(CN\fP is used for computer input.
|
|---|
| 127 | .br
|
|---|
| 128 | .fi
|
|---|
| 129 | .in +\n(INu
|
|---|
| 130 | .ti -\n(INu
|
|---|
| 131 | \(bu\|\^\*(FI\*(IN\fP is used for emphasis, to indicate user input and for syntactic
|
|---|
| 132 | placeholders, such as \*(FIvariable\fP or \*(FIaction\fP.
|
|---|
| 133 | .in -\n(INu
|
|---|
| 134 | .br
|
|---|
| 135 | \(bu \*(RN is used for explanatory text.
|
|---|
| 136 | .sp .5
|
|---|
| 137 | \*(FInumber\fP \- a floating point number as in ANSI C, such as
|
|---|
| 138 | \*(FC3\*(FR,
|
|---|
| 139 | \*(FC2.3\*(FR,
|
|---|
| 140 | \*(FC.4\*(FR,
|
|---|
| 141 | \*(FC1.4e2\*(FR
|
|---|
| 142 | or
|
|---|
| 143 | \*(FC4.1E5\*(FR.
|
|---|
| 144 | \*(CBNumbers may also be given in octal or hexadecimal: e.g.,
|
|---|
| 145 | \*(FC011\*(FR or \*(FC0x11\*(FR.\*(CD
|
|---|
| 146 | .sp .5
|
|---|
| 147 | \*(FIescape sequences\fP \- a special sequence of characters beginning
|
|---|
| 148 | with a backslash, used to describe otherwise unprintable characters.
|
|---|
| 149 | (See \fHEscape Sequences\fP below.)
|
|---|
| 150 | .sp .5
|
|---|
| 151 | \*(FIstring\fP \- a group of characters enclosed in double quotes.
|
|---|
| 152 | Strings may contain \*(FIescape sequences\*(FR.
|
|---|
| 153 | .sp .5
|
|---|
| 154 | \*(FIregexp\fP \- a regular expression, either a regexp constant
|
|---|
| 155 | enclosed in forward slashes, or a dynamic regexp computed at run-time.
|
|---|
| 156 | Regexp constants may contain \*(FIescape sequences\*(FR.
|
|---|
| 157 | .sp .5
|
|---|
| 158 | \*(FIname\fP \- a variable, array or function name.
|
|---|
| 159 | .sp .5
|
|---|
| 160 | \*(FIentry\fP(\*(FIN\fP) \- entry \*(FIentry\fP in section \*(FIN\fP of the
|
|---|
| 161 | UNIX reference manual.
|
|---|
| 162 | .sp .5
|
|---|
| 163 | \*(FIpattern\fP \- an expression describing an input record to be matched.
|
|---|
| 164 | .sp .5
|
|---|
| 165 | \*(FIaction\fP \- statements to execute when an input record is matched.
|
|---|
| 166 | .sp .5
|
|---|
| 167 | \*(FIrule\fP \- a pattern-action pair, where the pattern or action may
|
|---|
| 168 | be missing.\*(CX
|
|---|
| 169 | .EB "\s+2\f(HBDEFINITIONS\*(FR\s0"
|
|---|
| 170 |
|
|---|
| 171 | .\"
|
|---|
| 172 | .\"
|
|---|
| 173 | .\" --- Command Line Arguments
|
|---|
| 174 | .ES
|
|---|
| 175 | .fi
|
|---|
| 176 | \*(CDCommand line arguments control setting the field separator,
|
|---|
| 177 | setting variables before the \*(FCBEGIN\fP rule is run, and
|
|---|
| 178 | the location of AWK program source code.
|
|---|
| 179 | Implementation-specific command line arguments change
|
|---|
| 180 | the behavior of the running interpreter.
|
|---|
| 181 | .sp .5
|
|---|
| 182 | .TS
|
|---|
| 183 | expand;
|
|---|
| 184 | l lw(2.2i).
|
|---|
| 185 | \*(FC\-F \*(FIfs\*(FR use \*(FIfs\fP for the input field separator.
|
|---|
| 186 | \*(FC\-v\*(FI var\*(FC\^=\^\*(FIval\*(FR T{
|
|---|
| 187 | assign the value \*(FIval\*(FR to the variable \*(FIvar\*(FR
|
|---|
| 188 | before execution of the program begins. Such
|
|---|
| 189 | variable values are available to the \*(FCBEGIN\fP rule.
|
|---|
| 190 | T}
|
|---|
| 191 | \*(FC\-f \*(FIprog-file\*(FR T{
|
|---|
| 192 | read the AWK program source from the file
|
|---|
| 193 | \*(FIprog-file\*(FR, instead of from the first command
|
|---|
| 194 | line argument. Multiple \*(FC\-f\*(FR options may be used.
|
|---|
| 195 | T}
|
|---|
| 196 | \*(FC\-\^\-\*(FR signal the end of options.
|
|---|
| 197 | .TE
|
|---|
| 198 | .sp .5
|
|---|
| 199 | .fi
|
|---|
| 200 | \*(CLThe following options are accepted by both \*(NK and \*(GK
|
|---|
| 201 | \*(CR(ignored by \*(GK, not in \*(MK).\*(CL
|
|---|
| 202 | .sp .5
|
|---|
| 203 | .nf
|
|---|
| 204 | .TS
|
|---|
| 205 | expand, tab(%);
|
|---|
| 206 | l lw(2.2i).
|
|---|
| 207 | \*(FC\-mf \*(FIval\*(FR%set the maximum number of fields to \*(FIval\fP
|
|---|
| 208 | \*(FC\-mr \*(FIval\*(FR%set the maximum record size to \*(FIval\fP\*(CX
|
|---|
| 209 | .TE
|
|---|
| 210 | .EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (standard)\*(FR\s0"
|
|---|
| 211 |
|
|---|
| 212 | .\" --- Bug Reports
|
|---|
| 213 | .ES
|
|---|
| 214 | .fi
|
|---|
| 215 | \*(CDIf you find a bug in this reference card, please report it via electronic
|
|---|
| 216 | mail to \*([email protected]\*(FR.\*(CX
|
|---|
| 217 | .EB "\s+2\f(HBBUG REPORTS\*(FR\s0"
|
|---|
| 218 |
|
|---|
| 219 | .BT
|
|---|
| 220 |
|
|---|
| 221 | .\"
|
|---|
| 222 | .\"
|
|---|
| 223 | .\" --- Command Line Arguments (gawk)
|
|---|
| 224 | .ES
|
|---|
| 225 | .fi
|
|---|
| 226 | \*(CDThe following options are specific to \*(GK.
|
|---|
| 227 | You may also use ``\*(FC\-W \*(FIoption\*(FR''
|
|---|
| 228 | for full POSIX compliance.
|
|---|
| 229 | Long options may abbreviated as long as the abbreviation
|
|---|
| 230 | remains unique.
|
|---|
| 231 | .sp .5
|
|---|
| 232 | .ig
|
|---|
| 233 | .\" This option is left undocumented, on purpose.
|
|---|
| 234 | \*(FC\-\^\-nostalgia\*(FR%T{
|
|---|
| 235 | provide a moment of nostalgia for
|
|---|
| 236 | long time \*(AK users.
|
|---|
| 237 | T}
|
|---|
| 238 | ..
|
|---|
| 239 | .TS
|
|---|
| 240 | expand, tab(%);
|
|---|
| 241 | l lw(1.3i).
|
|---|
| 242 | \*(FC\-\^\-assign \*(FIvar\*(FC\^=\^\*(FIval\*(FR%just like \*(FC\-v\fP.
|
|---|
| 243 | \*(FC\-\^\-field-separator \*(FIfs\*(FR%just like \*(FC\-F\fP.
|
|---|
| 244 | \*(FC\-\^\-file \*(FIprog-file%\*(FRjust like \*(FC\-f\fP.
|
|---|
| 245 | .TE
|
|---|
| 246 | .TS
|
|---|
| 247 | expand, tab(%);
|
|---|
| 248 | ls
|
|---|
| 249 | l lw(2.2i).
|
|---|
| 250 | \*(FC\-\^\-compat\*(FR, \*(FC\-\^\-traditional\*(FR
|
|---|
| 251 | %T{
|
|---|
| 252 | disable \*(GK-specific extensions
|
|---|
| 253 | (the use of \*(FC\-\^\-traditional\*(FR is preferred).
|
|---|
| 254 | T}
|
|---|
| 255 | .T&
|
|---|
| 256 | ls
|
|---|
| 257 | l lw(2.2i).
|
|---|
| 258 | \*(FC\-\^\-copyleft\*(FR, \*(FC\-\^\-copyright\*(FR
|
|---|
| 259 | %T{
|
|---|
| 260 | print the short version of the GNU
|
|---|
| 261 | copyright information on \*(FCstdout\*(FR.
|
|---|
| 262 | T}
|
|---|
| 263 | .T&
|
|---|
| 264 | ls
|
|---|
| 265 | l lw(2.2i).
|
|---|
| 266 | \*(FC\-\^\-dump-variables\*(FR[\*(FC=\*(FIfile\*(FR]
|
|---|
| 267 | %T{
|
|---|
| 268 | print a sorted list of global variables,
|
|---|
| 269 | their types and final values to
|
|---|
| 270 | \*(FIfile\*(FR.
|
|---|
| 271 | If no \*(FIfile\*(FR
|
|---|
| 272 | is provided, \*(FCgawk\*(FR
|
|---|
| 273 | uses \*(FCawkvars.out\*(FR.
|
|---|
| 274 | T}
|
|---|
| 275 | \*(FC\-\^\-exec \*(FIfile\*(FR%T{
|
|---|
| 276 | read program text from \*(FIfile\fP. No other
|
|---|
| 277 | options are processed. Useful with \*(FC#!\fP.
|
|---|
| 278 | Also disables command-line variable assignments.
|
|---|
| 279 | T}
|
|---|
| 280 | \*(FC\-\^\-gen\-po\*(FR%T{
|
|---|
| 281 | process the program and print a GNU \*(FCgettext\*(FR
|
|---|
| 282 | format \*(FC\&.po\*(FR format file on standard output,
|
|---|
| 283 | containing the text of all strings that were marked
|
|---|
| 284 | for localization.
|
|---|
| 285 | T}
|
|---|
| 286 | .T&
|
|---|
| 287 | ls
|
|---|
| 288 | l lw(2.2i).
|
|---|
| 289 | \*(FC\-\^\-help\*(FR, \*(FC\-\^\-usage\*(FR
|
|---|
| 290 | %T{
|
|---|
| 291 | print a short summary of the available
|
|---|
| 292 | options on \*(FCstdout\*(FR, then exit zero.
|
|---|
| 293 | T}
|
|---|
| 294 | .T&
|
|---|
| 295 | ls
|
|---|
| 296 | l lw(2.2i).
|
|---|
| 297 | \*(FC\-\^\-lint\*(FR[\*(FC=\*(FIvalue\*(FR]
|
|---|
| 298 | %T{
|
|---|
| 299 | warn about constructs that are dubious
|
|---|
| 300 | or non-portable to other \*(AKs.
|
|---|
| 301 | With an optional argument of \*(FCfatal\*(FR,
|
|---|
| 302 | lint warnings become fatal errors.
|
|---|
| 303 | With an optional argument of
|
|---|
| 304 | \*(FCinvalid\*(FR,
|
|---|
| 305 | only warnings about things that are
|
|---|
| 306 | actually invalid are issued. (This is not fully implemented yet.)
|
|---|
| 307 | T}
|
|---|
| 308 | .T&
|
|---|
| 309 | l lw(2.2i).
|
|---|
| 310 | \*(FC\-\^\-lint\-old\*(FR%T{
|
|---|
| 311 | warn about constructs that are not
|
|---|
| 312 | portable to the original version of
|
|---|
| 313 | Unix \*(AK.
|
|---|
| 314 | T}
|
|---|
| 315 | .T&
|
|---|
| 316 | ls
|
|---|
| 317 | l lw(2.2i).
|
|---|
| 318 | \*(FC\-\^\-non\-decimal\-data\*(FR
|
|---|
| 319 | %T{
|
|---|
| 320 | recognize octal and hexadecimal values in input data.
|
|---|
| 321 | \*(FIUse this option with great caution!\*(FR
|
|---|
| 322 | T}
|
|---|
| 323 | .T&
|
|---|
| 324 | l lw(2.2i).
|
|---|
| 325 | \*(FC\-\^\-posix\*(FR%T{
|
|---|
| 326 | disable common and GNU extensions.
|
|---|
| 327 | Enable \*(FIinterval expressions\*(FR in regular
|
|---|
| 328 | expression matching (see \fHRegular
|
|---|
| 329 | Expressions\fP below).
|
|---|
| 330 | T}
|
|---|
| 331 | .T&
|
|---|
| 332 | ls
|
|---|
| 333 | l lw(2.2i).
|
|---|
| 334 | \*(FC\-\^\-profile\*(FR[\*(FC=\*(FIprof_file\*(FR]
|
|---|
| 335 | %T{
|
|---|
| 336 | send profiling data to \*(FIprof_file\*(FR
|
|---|
| 337 | (default: \*(FCawkprof.out\*(FR).
|
|---|
| 338 | With \*(GK,
|
|---|
| 339 | the profile is just a ``pretty printed'' version of the program.
|
|---|
| 340 | With \*(PK,
|
|---|
| 341 | the profile contains execution counts in the left margin
|
|---|
| 342 | of each statement in the program.
|
|---|
| 343 | T}
|
|---|
| 344 | .T&
|
|---|
| 345 | ls
|
|---|
| 346 | l lw(2.2i).
|
|---|
| 347 | \*(FC\-\^\-re\-interval\*(FR
|
|---|
| 348 | %T{
|
|---|
| 349 | enable \*(FIinterval expressions\*(FR in regular
|
|---|
| 350 | expression matching (see \fHRegular
|
|---|
| 351 | Expressions\fP below). Useful if
|
|---|
| 352 | \*(FC\-\^\-posix\*(FR is not specified.
|
|---|
| 353 | T}
|
|---|
| 354 | .T&
|
|---|
| 355 | ls
|
|---|
| 356 | l lw(2.2i).
|
|---|
| 357 | \*(FC\-\^\-source '\*(FItext\*(FC'\*(FR
|
|---|
| 358 | %use \*(FItext\*(FR as AWK program source code.
|
|---|
| 359 | \*(FC\-\^\-version\*(FR%T{
|
|---|
| 360 | print version information on \*(FCstdout\fP
|
|---|
| 361 | and exit zero.
|
|---|
| 362 | T}
|
|---|
| 363 | .TE
|
|---|
| 364 | .sp .5
|
|---|
| 365 | .fi
|
|---|
| 366 | In compatibility mode,
|
|---|
| 367 | any other options are flagged as invalid, but are otherwise ignored.
|
|---|
| 368 | In normal operation, as long as program text has been supplied, unknown
|
|---|
| 369 | options are passed on to the AWK program in
|
|---|
| 370 | \*(FCARGV\*(FR
|
|---|
| 371 | for processing. This is most useful for running AWK
|
|---|
| 372 | programs via the \*(FC#!\*(FR executable interpreter mechanism.\*(CB
|
|---|
| 373 | .EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 374 |
|
|---|
| 375 | .BT
|
|---|
| 376 |
|
|---|
| 377 | .\"
|
|---|
| 378 | .\"
|
|---|
| 379 | .\" --- Command Line Arguments (mawk)
|
|---|
| 380 | .ES
|
|---|
| 381 | .fi
|
|---|
| 382 | \*(CDThe following options are specific to \*(MK.
|
|---|
| 383 | .sp .5
|
|---|
| 384 | .fi
|
|---|
| 385 | .TS
|
|---|
| 386 | expand;
|
|---|
| 387 | l lw(1.8i).
|
|---|
| 388 | \*(FC\-W dump\*(FR T{
|
|---|
| 389 | print an assembly listing of the program to
|
|---|
| 390 | \*(FCstdout\fP and exit zero.
|
|---|
| 391 | T}
|
|---|
| 392 | \*(FC\-W exec \*(FIfile\*(FR T{
|
|---|
| 393 | read program text from \*(FIfile\fP. No other
|
|---|
| 394 | options are processed. Useful with \*(FC#!\fP.
|
|---|
| 395 | T}
|
|---|
| 396 | \*(FC\-W interactive\*(FR T{
|
|---|
| 397 | unbuffer \*(FCstdout\fP and line buffer \*(FCstdin\fP.
|
|---|
| 398 | Lines are always records, ignoring \*(FCRS\fP.
|
|---|
| 399 | T}
|
|---|
| 400 | \*(FC\-W posix_space\*(FR T{
|
|---|
| 401 | \*(FC\en\*(FR separates fields when \*(FCRS = "\^"\fP.
|
|---|
| 402 | T}
|
|---|
| 403 | \*(FC\-W sprintf=\*(FInum\*(FR T{
|
|---|
| 404 | adjust the size of \*(MK's internal
|
|---|
| 405 | \*(FCsprintf\*(FR buffer.
|
|---|
| 406 | T}
|
|---|
| 407 | \*(FC\-W version\*(FR T{
|
|---|
| 408 | print version and copyright on
|
|---|
| 409 | \*(FCstdout\fP and limit information on \*(FCstderr\fP
|
|---|
| 410 | and exit zero.
|
|---|
| 411 | T}
|
|---|
| 412 | .TE
|
|---|
| 413 | .sp .5
|
|---|
| 414 | .fi
|
|---|
| 415 | The options may be abbreviated using just the first letter, e.g.,
|
|---|
| 416 | \*(FC\-We\*(FR,
|
|---|
| 417 | \*(FC\-Wv\*(FR
|
|---|
| 418 | and so on.\*(CB
|
|---|
| 419 | .EB "\s+2\f(HBCOMMAND LINE ARGUMENTS (\*(MK\f(HB)\*(FR\s0"
|
|---|
| 420 | .sp .7
|
|---|
| 421 | .\" --- Signals (pgawk)
|
|---|
| 422 | .ES
|
|---|
| 423 | .fi
|
|---|
| 424 | \*(CD\*(PK accepts two signals.
|
|---|
| 425 | \*(FCSIGUSR1\fP dumps a profile and function call stack to the
|
|---|
| 426 | profile file. It then continues to run.
|
|---|
| 427 | \*(FCSIGHUP\fP is similar, but exits.\*(CB
|
|---|
| 428 | .EB "\s+2\f(HBSIGNALS (\*(PK\f(HB)\*(FR\s0"
|
|---|
| 429 | .sp .7
|
|---|
| 430 | .\" --- Awk Program Execution
|
|---|
| 431 | .ES
|
|---|
| 432 | .fi
|
|---|
| 433 | \*(CDAWK programs are a sequence of pattern-action statements
|
|---|
| 434 | and optional function definitions.
|
|---|
| 435 | .sp .5
|
|---|
| 436 | \*(FIpattern\*(FC { \*(FIaction statements\*(FC }\*(FR
|
|---|
| 437 | .br
|
|---|
| 438 | \*(FCfunction \*(FIname\*(FC(\*(FIparameter list\*(FC) { \*(FIstatements\*(FC }\*(FR
|
|---|
| 439 | .sp .5
|
|---|
| 440 | \*(AK first reads the program source from the
|
|---|
| 441 | \*(FIprog-file\*(FR(s), if specified,
|
|---|
| 442 | \*(CBfrom arguments to \*(FC\-\^\-source\*(FR,\*(CD
|
|---|
| 443 | or from the first non-option argument on the command line.
|
|---|
| 444 | The program text is read as if all the \*(FIprog-file\*(FR(s)
|
|---|
| 445 | \*(CBand command line
|
|---|
| 446 | source texts\*(CD had been concatenated.
|
|---|
| 447 | .sp .5
|
|---|
| 448 | AWK programs execute in the following order.
|
|---|
| 449 | First, all variable assignments specified via the \*(FC\-v\fP
|
|---|
| 450 | option are performed.
|
|---|
| 451 | Next, \*(AK executes the code in the
|
|---|
| 452 | \*(FCBEGIN\fP rules(s), if any, and then proceeds to read
|
|---|
| 453 | the files \*(FC1\fP through \*(FCARGC \- 1\fP in the \*(FCARGV\fP array.
|
|---|
| 454 | (Adjusting \*(FCARGC\fP and \*(FCARGV\fP thus provides control over
|
|---|
| 455 | the input files that will be processed.)
|
|---|
| 456 | If there are no files named on the command line,
|
|---|
| 457 | \*(AK reads the standard input.
|
|---|
| 458 | .sp .5
|
|---|
| 459 | If a command line argument has the form
|
|---|
| 460 | \*(FIvar\*(FC=\*(FIval\*(FR,
|
|---|
| 461 | it is treated as a variable assignment. The variable
|
|---|
| 462 | \*(FIvar\fP will be assigned the value \*(FIval\*(FR.
|
|---|
| 463 | (This happens after any \*(FCBEGIN\fP rule(s) have been run.)
|
|---|
| 464 | ... delete this paragraph if no space
|
|---|
| 465 | Command line variable assignment
|
|---|
| 466 | is most useful for dynamically assigning values to the variables
|
|---|
| 467 | \*(AK uses to control how input is broken into fields and records. It
|
|---|
| 468 | is also useful for controlling state if multiple passes are needed over
|
|---|
| 469 | a single data file.
|
|---|
| 470 | .sp .5
|
|---|
| 471 | If the value of a particular element of \*(FCARGV\fP is empty
|
|---|
| 472 | (\*(FC"\^"\*(FR), \*(AK skips over it.
|
|---|
| 473 | .sp .5
|
|---|
| 474 | For each record in the input, \*(AK tests to see if it matches any
|
|---|
| 475 | \*(FIpattern\fP in the AWK program.
|
|---|
| 476 | For each pattern that the record matches, the associated
|
|---|
| 477 | \*(FIaction\fP is executed.
|
|---|
| 478 | The patterns are tested in the order they occur in the program.
|
|---|
| 479 | .sp .5
|
|---|
| 480 | Finally, after all the input is exhausted,
|
|---|
| 481 | \*(AK executes the code in the \*(FCEND\fP rule(s), if any.
|
|---|
| 482 | .sp .5
|
|---|
| 483 | If a program only has a \*(FCBEGIN\fP rule, no input files are processed.
|
|---|
| 484 | If a program only has an \*(FCEND\fP rule, the input will be read.
|
|---|
| 485 | \*(CX
|
|---|
| 486 | .EB "\s+2\f(HBAWK PROGRAM EXECUTION\*(FR\s0"
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 | .BT
|
|---|
| 490 |
|
|---|
| 491 | .\" --- Lines And Statements
|
|---|
| 492 | .ES
|
|---|
| 493 | .fi
|
|---|
| 494 | \*(CDAWK is a line-oriented language. The pattern comes first, and then the
|
|---|
| 495 | action. Action statements are enclosed in \*(FC{\fP and \*(FC}\*(FR.
|
|---|
| 496 | Either the pattern or the action may be missing, but
|
|---|
| 497 | not both. If the pattern is missing, the action is
|
|---|
| 498 | executed for every input record.
|
|---|
| 499 | A missing action is equivalent to
|
|---|
| 500 | .sp .5
|
|---|
| 501 | \*(FC{ print }\fP
|
|---|
| 502 | .sp .5
|
|---|
| 503 | which prints the entire record.
|
|---|
| 504 | .sp .5
|
|---|
| 505 | Comments begin with the \*(FC#\*(FR character, and continue until the
|
|---|
| 506 | end of the line.
|
|---|
| 507 | Normally, a statement ends with a newline, but lines ending in
|
|---|
| 508 | a ``,'',
|
|---|
| 509 | \*(FC{\*(FR,
|
|---|
| 510 | \*(CB\*(FC?\*(FR,
|
|---|
| 511 | \*(FC:\*(FR,\*(CD
|
|---|
| 512 | \*(FC&&\*(FR
|
|---|
| 513 | or
|
|---|
| 514 | \*(FC||\*(FR
|
|---|
| 515 | are automatically continued.
|
|---|
| 516 | Lines ending in \*(FCdo\fP or \*(FCelse\fP
|
|---|
| 517 | also have their statements automatically continued on the following line.
|
|---|
| 518 | In other cases, a line can be continued by ending it with a ``\e'',
|
|---|
| 519 | in which case the newline is ignored. However, a ``\e'' after a
|
|---|
| 520 | \*(FC#\*(FR is not special.
|
|---|
| 521 | .sp .5
|
|---|
| 522 | Multiple statements may be put on one line by separating them with a ``;''.
|
|---|
| 523 | This applies to both the statements within the action part of a
|
|---|
| 524 | pattern-action pair (the usual case)
|
|---|
| 525 | and to the pattern-action statements themselves.\*(CX
|
|---|
| 526 | .EB "\s+2\f(HBLINES AND STATEMENTS\*(FR\s0"
|
|---|
| 527 |
|
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 | .\" --- Regular Expressions
|
|---|
| 531 | .ES
|
|---|
| 532 | .fi
|
|---|
| 533 | \*(CDRegular expressions are the extended kind originally defined by
|
|---|
| 534 | \*(FCegrep\fP.
|
|---|
| 535 | \*(CBAdditional GNU regexp operators are supported by \*(GK.
|
|---|
| 536 | A \*(FIword-constituent\fP character is a letter, digit, or
|
|---|
| 537 | underscore (\*(FC_\fP).\*(CD
|
|---|
| 538 | .sp .5
|
|---|
| 539 | .TS
|
|---|
| 540 | center, tab(~);
|
|---|
| 541 | cp8 sp8
|
|---|
| 542 | cp8 sp8
|
|---|
| 543 | lp8|lp8.
|
|---|
| 544 | .\" .vs 10
|
|---|
| 545 | _
|
|---|
| 546 | Summary of Regular Expressions
|
|---|
| 547 | In Decreasing Precedence
|
|---|
| 548 | _
|
|---|
| 549 | \*(FC(\^\*(FIr\*(FC)\*(FR~regular expression (for grouping)
|
|---|
| 550 | \*(FIc\*(FR~if non-special char, matches itself
|
|---|
| 551 | \*(FC\e\*(FI\^c\*(FR~turn off special meaning of \*(FIc\fP
|
|---|
| 552 | \*(FC^\*(FR~beginning of string (note: \*(FInot\fP line)
|
|---|
| 553 | \*(FC$\*(FR~end of string (note: \*(FInot\fP line)
|
|---|
| 554 | \*(FC.\*(FR~any single character, including newline
|
|---|
| 555 | \*(FC[\*(FR...\*(FC]\*(FR~any one character in ... or range
|
|---|
| 556 | \*(FC[^\*(FR...\*(FC]\*(FR~any one character not in ... or range
|
|---|
| 557 | \*(CB\*(FC\ey\*(FR~word boundary
|
|---|
| 558 | \*(FC\eB\*(FR~middle of a word
|
|---|
| 559 | \*(FC\e<\*(FR~beginning of a word
|
|---|
| 560 | \*(FC\e>\*(FR~end of a word
|
|---|
| 561 | \*(FC\ew\*(FR~any word-constituent character
|
|---|
| 562 | \*(FC\eW\*(FR~any non-word-constituent character
|
|---|
| 563 | \*(FC\e`\*(FR~beginning of a string
|
|---|
| 564 | \*(FC\e'\*(FR~end of a string\*(CD
|
|---|
| 565 | \*(FIr\*(FC*\*(FR~zero or more occurrences of \*(FIr\*(FR
|
|---|
| 566 | \*(FIr\*(FC+\*(FR~one or more occurrences of \*(FIr\*(FR
|
|---|
| 567 | \*(FIr\*(FC?\*(FR~zero or one occurrences of \*(FIr\*(FR
|
|---|
| 568 | \*(FIr\*(FC{\*(FIn\*(FC,\*(FIm\*(FC}\*(FR~\*(FIn\fP to \*(FIm\fP occurrences of \*(FIr\*(FR \*(CR(POSIX: see note below)\*(CD
|
|---|
| 569 | \*(FIr1\*(FC|\|\*(FIr2\*(FR~\*(FIr1\*(FR or \*(FIr2\*(FR
|
|---|
| 570 | .TE
|
|---|
| 571 | .sp .5
|
|---|
| 572 | .fi
|
|---|
| 573 | \*(CRThe \*(FIr\*(FC{\*(FIn\*(FC,\*(FIm\*(FC}\*(FR notation is called an
|
|---|
| 574 | \*(FIinterval expression\fP. POSIX mandates it for AWK regexps, but
|
|---|
| 575 | most \*(AKs don't implement it. \*(CBUse \*(FC\-\^\-re\-interval\*(FR
|
|---|
| 576 | or \*(FC\-\^\-posix\*(FR to enable
|
|---|
| 577 | this feature in \*(GK.\*(CX
|
|---|
| 578 | .EB "\s+2\f(HBREGULAR EXPRESSIONS\*(FR\s0"
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 | .BT
|
|---|
| 582 |
|
|---|
| 583 | .\" --- POSIX Character Classes (gawk)
|
|---|
| 584 | .ES
|
|---|
| 585 | .fi
|
|---|
| 586 | \*(CDIn regular expressions, within character ranges
|
|---|
| 587 | (\*(FC[\*(FR...\*(FC]\*(FR),
|
|---|
| 588 | the notation \*(FC[[:\*(FIclass\*(FC:]]\*(FR defines character classes:
|
|---|
| 589 | .sp .5
|
|---|
| 590 | .TS
|
|---|
| 591 | center, tab(~);
|
|---|
| 592 | lp8 lp8 lp8 lp8.
|
|---|
| 593 | \*(FCalnum\*(FR~alphanumeric~\*(FClower\*(FR~lower-case
|
|---|
| 594 | \*(FCalpha\*(FR~alphabetic~\*(FCprint\*(FR~printable
|
|---|
| 595 | \*(FCblank\*(FR~space or tab~\*(FCpunct\*(FR~punctuation
|
|---|
| 596 | \*(FCcntrl\*(FR~control~\*(FCspace\*(FR~whitespace
|
|---|
| 597 | \*(FCdigit\*(FR~decimal~\*(FCupper\*(FR~upper-case
|
|---|
| 598 | \*(FCgraph\*(FR~non-spaces~\*(FCxdigit\*(FR~hexadecimal
|
|---|
| 599 | .TE
|
|---|
| 600 | .fi
|
|---|
| 601 | .sp .5
|
|---|
| 602 | Recognition of these character classes is disabled
|
|---|
| 603 | when \*(FC\-\-traditional\*(FR is supplied.\*(CB
|
|---|
| 604 | .EB "\s+2\f(HBPOSIX CHARACTER CLASSES (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 605 |
|
|---|
| 606 | .\" --- Records
|
|---|
| 607 | .ES
|
|---|
| 608 | .fi
|
|---|
| 609 | \*(CDNormally, records are separated by newline characters.
|
|---|
| 610 | Assigning values to the built-in variable \*(FCRS\*(FR
|
|---|
| 611 | controls how records are separated.
|
|---|
| 612 | If \*(FCRS\fP is any single character, that character separates records.
|
|---|
| 613 | \*(CLOtherwise, \*(FCRS\fP is a regular expression.
|
|---|
| 614 | \*(CR(Not \*(NK.)\*(CL
|
|---|
| 615 | Text in the input that matches this
|
|---|
| 616 | regular expression separates the record.
|
|---|
| 617 | \*(CB\*(GK sets \*(FCRT\*(FR to the value of the
|
|---|
| 618 | input text that matched the regular expression.
|
|---|
| 619 | The value of \*(FCIGNORECASE\fP
|
|---|
| 620 | also affects how records are separated when
|
|---|
| 621 | \*(FCRS\fP is a regular expression.\*(CD
|
|---|
| 622 | If \*(FCRS\fP is set to the null string,
|
|---|
| 623 | then records are separated by one or more blank lines.
|
|---|
| 624 | When \*(FCRS\fP is set to the null string,
|
|---|
| 625 | the newline character always acts as
|
|---|
| 626 | a field separator, in addition to whatever value
|
|---|
| 627 | \*(FCFS\fP may have.
|
|---|
| 628 | \*(CB\*(MK does not apply exceptional rules to \*(FCFS\fP
|
|---|
| 629 | when \*(FCRS = "\^"\fP.\*(CX
|
|---|
| 630 | .EB "\s+2\f(HBRECORDS\*(FR\s0"
|
|---|
| 631 |
|
|---|
| 632 | .\" --- Fields
|
|---|
| 633 | .ES
|
|---|
| 634 | .fi
|
|---|
| 635 | \*(CDAs each input record is read, \*(AK splits the record into
|
|---|
| 636 | \*(FIfields\*(FR, using the value of the \*(FCFS\fP
|
|---|
| 637 | variable as the field separator.
|
|---|
| 638 | If \*(FCFS\fP is a single character,
|
|---|
| 639 | fields are separated by that character.
|
|---|
| 640 | \*(CLIf \*(FCFS\fP is the null string,
|
|---|
| 641 | then each individual character becomes a separate field.\*(CD
|
|---|
| 642 | Otherwise, \*(FCFS\fP is expected to be a full regular expression.
|
|---|
| 643 | In the special case that \*(FCFS\fP
|
|---|
| 644 | is a single space, fields are separated
|
|---|
| 645 | by runs of spaces and/or tabs
|
|---|
| 646 | \*(CLand/or newlines\*(CD.
|
|---|
| 647 | Leading and trailing whitespace are ignored.
|
|---|
| 648 | \*(CBThe value of \*(FCIGNORECASE\fP
|
|---|
| 649 | also affects how fields are split when
|
|---|
| 650 | \*(FCFS\fP is a regular expression.\*(CD
|
|---|
| 651 | .sp .5
|
|---|
| 652 | \*(CBIf the \*(FCFIELDWIDTHS\fP
|
|---|
| 653 | variable is set to a space-separated list of numbers, each field is
|
|---|
| 654 | expected to have a fixed width, and \*(GK
|
|---|
| 655 | splits up the record using the specified widths.
|
|---|
| 656 | The value of \*(FCFS\fP is ignored.
|
|---|
| 657 | Assigning a new value to \*(FCFS\fP
|
|---|
| 658 | overrides the use of \*(FCFIELDWIDTHS\*(FR,
|
|---|
| 659 | and restores the default behavior.\*(CD
|
|---|
| 660 | .sp .5
|
|---|
| 661 | Each field in the input record may be referenced by its position,
|
|---|
| 662 | \*(FC$1\*(FR, \*(FC$2\*(FR and so on.
|
|---|
| 663 | \*(FC$0\fP is the whole record.
|
|---|
| 664 | Fields may also be assigned new values.
|
|---|
| 665 | .sp .5
|
|---|
| 666 | The variable \*(FCNF\fP
|
|---|
| 667 | is set to the total number of fields in the input record.
|
|---|
| 668 | .sp .5
|
|---|
| 669 | References to non-existent fields (i.e., fields after \*(FC$NF\*(FR)
|
|---|
| 670 | produce the null-string. However, assigning to a non-existent field
|
|---|
| 671 | (e.g., \*(FC$(NF+2) = 5\*(FR) increases the value of
|
|---|
| 672 | \*(FCNF\*(FR, creates any intervening fields with the null string as their value,
|
|---|
| 673 | and causes the value of \*(FC$0\fP
|
|---|
| 674 | to be recomputed with the fields being separated by the
|
|---|
| 675 | value of \*(FCOFS\*(FR.
|
|---|
| 676 | References to negative numbered fields cause a fatal error.
|
|---|
| 677 | Decreasing the value of \*(FCNF\fP causes the trailing fields to be lost
|
|---|
| 678 | \*(CR(not \*(NK).\*(CX
|
|---|
| 679 | .EB "\s+2\f(HBFIELDS\*(FR\s0"
|
|---|
| 680 |
|
|---|
| 681 | .BT
|
|---|
| 682 |
|
|---|
| 683 | .\" --- Pattern Elements
|
|---|
| 684 | .ES
|
|---|
| 685 | .fi
|
|---|
| 686 | \*(CDAWK patterns may be one of the following.
|
|---|
| 687 | .sp .5
|
|---|
| 688 | .nf
|
|---|
| 689 | \*(FCBEGIN
|
|---|
| 690 | END
|
|---|
| 691 | \*(FIexpression
|
|---|
| 692 | pat1\*(FC,\*(FIpat2\*(FR
|
|---|
| 693 | .sp .5
|
|---|
| 694 | .fi
|
|---|
| 695 | \*(FCBEGIN\fP and \*(FCEND\fP are special patterns that provide start-up
|
|---|
| 696 | and clean-up actions respectively. They must have actions. There can
|
|---|
| 697 | be multiple \*(FCBEGIN\fP and \*(FCEND\fP rules; they are merged and
|
|---|
| 698 | executed as if there had just been one large rule. They may occur anywhere
|
|---|
| 699 | in a program, including different source files.
|
|---|
| 700 | .sp .5
|
|---|
| 701 | Expression patterns can be any expression, as described
|
|---|
| 702 | under \fHExpressions\fP.
|
|---|
| 703 | .sp .5
|
|---|
| 704 | The \*(FIpat1\*(FC,\*(FIpat2\*(FR pattern
|
|---|
| 705 | is called a \*(FIrange pattern\*(FR.
|
|---|
| 706 | It matches all input records starting with a record that matches
|
|---|
| 707 | \*(FIpat1\*(FR, and continuing until a record that matches
|
|---|
| 708 | \*(FIpat2\*(FR, inclusive.
|
|---|
| 709 | It does not combine with any other pattern expression.\*(CX
|
|---|
| 710 | .EB "\s+2\f(HBPATTERN ELEMENTS\*(FR\s0"
|
|---|
| 711 |
|
|---|
| 712 |
|
|---|
| 713 | .\" --- Action Statements
|
|---|
| 714 | .ES
|
|---|
| 715 | .fi
|
|---|
| 716 | .in +.2i
|
|---|
| 717 | .ti -.2i
|
|---|
| 718 | \*(CD\*(FCbreak\*(FR
|
|---|
| 719 | .br
|
|---|
| 720 | break out of the nearest enclosing \*(FCdo\*(FR, \*(FCfor\*(FR,
|
|---|
| 721 | or \*(FCwhile\*(FR loop.
|
|---|
| 722 | .ti -.2i
|
|---|
| 723 | \*(FCcontinue\*(FR
|
|---|
| 724 | .br
|
|---|
| 725 | skip the rest of the loop body.
|
|---|
| 726 | Evaluate the \*(FIcondition\*(FR
|
|---|
| 727 | part of the nearest enclosing \*(FCdo\*(FR or \*(FCwhile\*(FR loop,
|
|---|
| 728 | or go to the \*(FIincr\*(FR part of a \*(FCfor\*(FR loop.
|
|---|
| 729 | .ti -.2i
|
|---|
| 730 | \*(FCdelete \*(FIarray\^\*(FC[\^\*(FIindex\^\*(FC]\*(FR
|
|---|
| 731 | .br
|
|---|
| 732 | delete element \*(FIindex\*(FR from array \*(FIarray\*(FR.
|
|---|
| 733 | .ti -.2i
|
|---|
| 734 | \*(CL\*(FCdelete \*(FIarray\^\*(FR
|
|---|
| 735 | .br
|
|---|
| 736 | delete all elements from array \*(FIarray\*(FR.\*(CD
|
|---|
| 737 | .ti -.2i
|
|---|
| 738 | \*(FCdo \*(FIstatement \*(FCwhile (\*(FIcondition\*(FC)\*(FR
|
|---|
| 739 | .br
|
|---|
| 740 | execute \*(FIstatement\*(FR while \*(FIcondition\*(FR is true.
|
|---|
| 741 | The \*(FIstatement\*(FR is always executed at least once.
|
|---|
| 742 | .ti -.2i
|
|---|
| 743 | \*(FCexit\*(FR [ \*(FIexpression\*(FR ]
|
|---|
| 744 | .br
|
|---|
| 745 | terminate input record processing.
|
|---|
| 746 | Execute the \*(FCEND\*(FR rule(s) if present.
|
|---|
| 747 | If present, \*(FIexpression\*(FR becomes \*(AK's return value.
|
|---|
| 748 | .ti -.2i
|
|---|
| 749 | \*(FCfor (\*(FIinit\*(FC; \*(FIcond\*(FC; \*(FIincr\*(FC) \*(FIstatement\*(FR
|
|---|
| 750 | .br
|
|---|
| 751 | execute \*(FIinit\*(FR.
|
|---|
| 752 | Evaluate \*(FIcond\*(FR.
|
|---|
| 753 | If it is true, execute \*(FIstatement\*(FR.
|
|---|
| 754 | Execute \*(FIincr\*(FR before going back to the top to
|
|---|
| 755 | re-evaluate \*(FIcond\*(FR.
|
|---|
| 756 | Any of the three may be omitted.
|
|---|
| 757 | A missing \*(FIcond\*(FR is considered to be true.
|
|---|
| 758 | .ti -.2i
|
|---|
| 759 | \*(FCfor (\*(FIvar \*(FCin\*(FI array\*(FC) \*(FIstatement\*(FR
|
|---|
| 760 | .br
|
|---|
| 761 | execute \*(FIstatement\*(FR once for each subscript in \*(FIarray\*(FR,
|
|---|
| 762 | with \*(FIvar\*(FR set to a different subscript each time through
|
|---|
| 763 | the loop.
|
|---|
| 764 | .ti -.2i
|
|---|
| 765 | \*(CD\*(FCif (\*(FIcondition\*(FC) \*(FIstatement1\*(FR [ \*(FCelse\*(FI statement2\*(FR ]
|
|---|
| 766 | .br
|
|---|
| 767 | if \*(FIcondition\*(FR is true, execute \*(FIstatement1\*(FR,
|
|---|
| 768 | otherwise execute \*(FIstatement2\*(FR. Each \*(FCelse\*(FR
|
|---|
| 769 | matches the closest \*(FCif\*(FR.
|
|---|
| 770 | .ti -.2i
|
|---|
| 771 | \*(FCnext\*(FR see \fHInput Control.\fP
|
|---|
| 772 | .ti -.2i
|
|---|
| 773 | \*(CL\*(FCnextfile\*(FR \*(CR(not \*(MK) \*(CLsee \fHInput Control.\fP\*(CD
|
|---|
| 774 | .ti -.2i
|
|---|
| 775 | .\" --- Start switch statement
|
|---|
| 776 | \*(CB\*(FCswitch (\*(FIexpression\*(FC) {
|
|---|
| 777 | .br
|
|---|
| 778 | case [\*(FIvalue\*(FC|\*(FIregular expression\*(FC] : \*(FIstatement(s)\*(FC
|
|---|
| 779 | .br
|
|---|
| 780 | default: \*(FIstatement(s)\*(FC
|
|---|
| 781 | .br
|
|---|
| 782 | }\*(FR
|
|---|
| 783 | .br
|
|---|
| 784 | switch on \*(FIexpression\*(FR, execute \*(FIcase\*(FR if matched, default if not.
|
|---|
| 785 | For 3.1.x, requires \*(FC\-\^\-enable\-switch\*(FR option to \*(FCconfigure\*(FR.\*(CD
|
|---|
| 786 | .ti -.2i
|
|---|
| 787 | .\" --- End switch statement
|
|---|
| 788 | \*(FCwhile (\*(FIcondition\*(FC) \*(FIstatement \*(FR
|
|---|
| 789 | .br
|
|---|
| 790 | while \*(FIcondition\*(FR is true, execute \*(FIstatement\*(FR.
|
|---|
| 791 | .ti -.2i
|
|---|
| 792 | \*(FC{ \*(FIstatements \*(FC}\*(FR
|
|---|
| 793 | .br
|
|---|
| 794 | a list of statements enclosed in braces can be used anywhere
|
|---|
| 795 | that a single statement would otherwise be used.\*(CX
|
|---|
| 796 | .in -.2i
|
|---|
| 797 | .EB "\s+2\f(HBACTION STATEMENTS\*(FR\s0"
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 | .BT
|
|---|
| 801 |
|
|---|
| 802 | .\" --- Escape Sequences
|
|---|
| 803 | .ES
|
|---|
| 804 | .fi
|
|---|
| 805 | \*(CDWithin strings constants (\*(FC"..."\fP) and regexp
|
|---|
| 806 | constants (\*(FC/.../\fP), escape sequences may be used to
|
|---|
| 807 | generate otherwise unprintable characters. This table lists
|
|---|
| 808 | the available escape sequences.
|
|---|
| 809 | .sp .5
|
|---|
| 810 | .TS
|
|---|
| 811 | center, tab(~);
|
|---|
| 812 | lp8 lp8 lp8 lp8.
|
|---|
| 813 | \*(FC\ea\fP~alert (bell)~\*(FC\er\fP~carriage return
|
|---|
| 814 | \*(FC\eb\fP~backspace~\*(FC\et\fP~horizontal tab
|
|---|
| 815 | \*(FC\ef\fP~form feed~\*(FC\ev\fP~vertical tab
|
|---|
| 816 | \*(FC\en\fP~newline~\*(FC\e\e\fP~backslash
|
|---|
| 817 | \*(FC\e\*(FIddd\*(FR~octal value \*(FIddd\fP~\*(CL\*(FC\ex\*(FIhh\*(FR~hex value \*(FIhh\fP\*(CD
|
|---|
| 818 | \*(FC\e"\fP~double quote~\*(FC\e/\fP~forward slash\*(CX
|
|---|
| 819 | .TE
|
|---|
| 820 | .EB "\s+2\f(HBESCAPE SEQUENCES\*(FR\s0"
|
|---|
| 821 | .sp .7
|
|---|
| 822 | .\" --- Variables
|
|---|
| 823 | .ES
|
|---|
| 824 | .fi
|
|---|
| 825 | .TS
|
|---|
| 826 | expand;
|
|---|
| 827 | l lw(2i).
|
|---|
| 828 | \*(CD\*(FCARGC\fP T{
|
|---|
| 829 | number of command line arguments.
|
|---|
| 830 | T}
|
|---|
| 831 | \*(CB\*(FCARGIND\fP T{
|
|---|
| 832 | index in \*(FCARGV\fP of current data file.\*(CD
|
|---|
| 833 | T}
|
|---|
| 834 | \*(FCARGV\fP T{
|
|---|
| 835 | array of command line arguments. Indexed from
|
|---|
| 836 | 0 to \*(FCARGC\fP \- 1. Dynamically changing the
|
|---|
| 837 | contents of \*(FCARGV\fP can control the files used
|
|---|
| 838 | for data.
|
|---|
| 839 | T}
|
|---|
| 840 | \*(CL\*(FCBINMODE\fP T{
|
|---|
| 841 | controls ``binary'' mode for all file I/O. Values of 1, 2, or 3,
|
|---|
| 842 | indicate input, output, or all files, respectively, should use binary
|
|---|
| 843 | I/O. \*(CR(Not \*(NK.) \*(CLApplies only to non-POSIX systems.
|
|---|
| 844 | \*(CBFor \*(GK, string values of \*(FC"r"\fP, or \*(FC"w"\fP specify
|
|---|
| 845 | that input files, or output files, respectively, should use binary I/O.
|
|---|
| 846 | String values of \*(FC"rw"\fP or \*(FC"wr"\fP specify that all files
|
|---|
| 847 | should use binary I/O. Any other string value is treated as \*(FC"rw"\fP,
|
|---|
| 848 | but generates a warning message.\*(CD
|
|---|
| 849 | T}
|
|---|
| 850 | \*(FCCONVFMT\fP T{
|
|---|
| 851 | conversion format for numbers, default value
|
|---|
| 852 | is \*(FC"%.6g"\*(FR.
|
|---|
| 853 | T}
|
|---|
| 854 | \*(FCENVIRON\fP T{
|
|---|
| 855 | array containing the current environment.
|
|---|
| 856 | The array is indexed by the environment
|
|---|
| 857 | variables, each element being the value of
|
|---|
| 858 | that variable.
|
|---|
| 859 | T}
|
|---|
| 860 | \*(CB\*(FCERRNO\fP T{
|
|---|
| 861 | string describing the error if a
|
|---|
| 862 | \*(FCgetline\*(FR
|
|---|
| 863 | redirection or read
|
|---|
| 864 | fails, or if
|
|---|
| 865 | \*(FCclose()\*(FR fails.
|
|---|
| 866 | T}
|
|---|
| 867 | \*(FCFIELDWIDTHS\fP T{
|
|---|
| 868 | white-space separated list of fieldwidths. Used
|
|---|
| 869 | to parse the input into fields of fixed width,
|
|---|
| 870 | instead of the value of \*(FCFS\fP.\*(CD
|
|---|
| 871 | T}
|
|---|
| 872 | \*(FCFILENAME\fP T{
|
|---|
| 873 | name of the current input file. If no files given
|
|---|
| 874 | on the command line, \*(FCFILENAME\fP is ``\-''.
|
|---|
| 875 | \*(FCFILENAME\fP is undefined inside the \*(FCBEGIN\fP rule
|
|---|
| 876 | (unless set by \*(FCgetline\fP).
|
|---|
| 877 | T}
|
|---|
| 878 | \*(FCFNR\fP T{
|
|---|
| 879 | record number in current input file.
|
|---|
| 880 | T}
|
|---|
| 881 | \*(FCFS\fP T{
|
|---|
| 882 | input field separator, a space by default
|
|---|
| 883 | (see \fHFields\fP above).
|
|---|
| 884 | T}
|
|---|
| 885 | \*(CB\*(FCIGNORECASE\fP T{
|
|---|
| 886 | if non-zero, all regular expression and string
|
|---|
| 887 | operations ignore case.
|
|---|
| 888 | Array subscripting
|
|---|
| 889 | is \*(FInot\*(FR affected.
|
|---|
| 890 | However, the
|
|---|
| 891 | \*(FCasort()\*(FR
|
|---|
| 892 | and
|
|---|
| 893 | \*(FCasorti()\*(FR
|
|---|
| 894 | function are affected.
|
|---|
| 895 | T}
|
|---|
| 896 | \*(CB\*(FCLINT\fP T{
|
|---|
| 897 | provides dynamic control of the \*(FC\-\^\-lint\fP
|
|---|
| 898 | option from within an AWK program.
|
|---|
| 899 | When true, \*(GK
|
|---|
| 900 | prints lint warnings.
|
|---|
| 901 | When assigned the string value \*(FC"fatal"\*(FR,
|
|---|
| 902 | lint warnings become fatal errors, exactly like
|
|---|
| 903 | \*(FC\-\-lint=fatal\*(FR.
|
|---|
| 904 | Any other true value just prints warnings.\*(CD
|
|---|
| 905 | T}
|
|---|
| 906 | \*(FCNF\fP T{
|
|---|
| 907 | number of fields in the current input record.
|
|---|
| 908 | T}
|
|---|
| 909 | \*(FCNR\fP T{
|
|---|
| 910 | total number of input records seen so far.\*(CX
|
|---|
| 911 | T}
|
|---|
| 912 | .TE
|
|---|
| 913 | .EB "\s+2\f(HBVARIABLES\*(FR\s0"
|
|---|
| 914 | .BT
|
|---|
| 915 |
|
|---|
| 916 | .\" --- Variables (continued)
|
|---|
| 917 | .ES
|
|---|
| 918 | .fi
|
|---|
| 919 | .TS
|
|---|
| 920 | expand;
|
|---|
| 921 | l lw(2i).
|
|---|
| 922 | \*(CD\*(FCOFMT\fP T{
|
|---|
| 923 | output format for numbers, \*(FC"%.6g"\*(FR, by default.
|
|---|
| 924 | \*(CROld versions of \*(AK used this for number
|
|---|
| 925 | to string conversion.\*(CD
|
|---|
| 926 | T}
|
|---|
| 927 | \*(FCOFS\fP T{
|
|---|
| 928 | output field separator, a space by default.
|
|---|
| 929 | T}
|
|---|
| 930 | \*(FCORS\fP T{
|
|---|
| 931 | output record separator, a newline by default.
|
|---|
| 932 | T}
|
|---|
| 933 | \*(CB\*(FCPROCINFO\fP T{
|
|---|
| 934 | elements of this array provide access to info
|
|---|
| 935 | about the running AWK program. See
|
|---|
| 936 | \*(AM for details.\*(CD
|
|---|
| 937 | T}
|
|---|
| 938 | \*(FCRLENGTH\fP T{
|
|---|
| 939 | length of the string matched by \*(FCmatch()\*(FR;
|
|---|
| 940 | \-1 if no match.
|
|---|
| 941 | T}
|
|---|
| 942 | \*(FCRS\fP T{
|
|---|
| 943 | input record separator, a newline by default
|
|---|
| 944 | (see \fHRecords\fP above).
|
|---|
| 945 | T}
|
|---|
| 946 | \*(FCRSTART\fP T{
|
|---|
| 947 | index of the first character matched by
|
|---|
| 948 | \*(FCmatch()\*(FR; 0 if no match.
|
|---|
| 949 | T}
|
|---|
| 950 | \*(CB\*(FCRT\fP T{
|
|---|
| 951 | record terminator. \*(GK sets \*(FCRT\fP to the input
|
|---|
| 952 | text that matched the character or regular
|
|---|
| 953 | expression specified by \*(FCRS\*(FR.\*(CD
|
|---|
| 954 | T}
|
|---|
| 955 | \*(FCSUBSEP\fP T{
|
|---|
| 956 | character(s) used to separate multiple subscripts
|
|---|
| 957 | in array elements, by default \*(FC"\e034"\*(FR. (See
|
|---|
| 958 | \fHArrays\fP below).
|
|---|
| 959 | T}
|
|---|
| 960 | \*(CB\*(FCTEXTDOMAIN\fP T{
|
|---|
| 961 | the application's text domain for internationalization;
|
|---|
| 962 | used to find the localized
|
|---|
| 963 | translations for the program's strings.\*(CX
|
|---|
| 964 | T}
|
|---|
| 965 | .TE
|
|---|
| 966 | .EB "\s+2\f(HBVARIABLES (continued)\*(FR\s0"
|
|---|
| 967 |
|
|---|
| 968 | .\" --- Conversions and Comparisons
|
|---|
| 969 | .ES
|
|---|
| 970 | .fi
|
|---|
| 971 | \*(CDVariables and fields may be (floating point) numbers, strings or both.
|
|---|
| 972 | Context determines how the value of a variable is interpreted. If used in
|
|---|
| 973 | a numeric expression, it will be treated as a number, if used as a string
|
|---|
| 974 | it will be treated as a string.
|
|---|
| 975 | .sp .5
|
|---|
| 976 | To force a variable to be treated as a number, add 0 to it; to force it
|
|---|
| 977 | to be treated as a string, concatenate it with the null string.
|
|---|
| 978 | .sp .5
|
|---|
| 979 | When a string must be converted to a number, the conversion is accomplished
|
|---|
| 980 | using \*(FIstrtod\*(FR(3).
|
|---|
| 981 | A number is converted to a string by using the value of \*(FCCONVFMT\fP
|
|---|
| 982 | as a format string for \*(FIsprintf\*(FR(3),
|
|---|
| 983 | with the numeric value of the variable as the argument.
|
|---|
| 984 | However, even though all numbers in AWK are floating-point,
|
|---|
| 985 | integral values are \*(FIalways\fP converted as integers.
|
|---|
| 986 | .sp .5
|
|---|
| 987 | Comparisons are performed as follows:
|
|---|
| 988 | If two variables are numeric, they are compared numerically.
|
|---|
| 989 | If one value is numeric and the other has a string value that is a
|
|---|
| 990 | ``numeric string,'' then comparisons are also done numerically.
|
|---|
| 991 | Otherwise, the numeric value is converted to a string, and a string
|
|---|
| 992 | comparison is performed.
|
|---|
| 993 | Two strings are compared, of course, as strings.
|
|---|
| 994 | .sp .5
|
|---|
| 995 | Note that string constants, such as \*(FC"57"\fP, are \*(FInot\fP
|
|---|
| 996 | numeric strings, they are string constants. The idea of ``numeric string''
|
|---|
| 997 | only applies to fields, \*(FCgetline\fP input,
|
|---|
| 998 | \*(FCFILENAME\*(FR, \*(FCARGV\fP elements, \*(FCENVIRON\fP
|
|---|
| 999 | elements and the elements of an array created by
|
|---|
| 1000 | \*(FCsplit()\fP that are numeric strings.
|
|---|
| 1001 | The basic idea is that \*(FIuser input\*(FR,
|
|---|
| 1002 | and only user input, that looks numeric,
|
|---|
| 1003 | should be treated that way.
|
|---|
| 1004 | \*(CRNote that the POSIX standard applies the concept of
|
|---|
| 1005 | ``numeric string'' everywhere, even to string constants.
|
|---|
| 1006 | However, this is
|
|---|
| 1007 | clearly incorrect, and none of the three free \*(AK\*(FRs do this.\*(CD
|
|---|
| 1008 | (Fortunately, this is fixed in the next version of the standard.)
|
|---|
| 1009 | .sp .5
|
|---|
| 1010 | Uninitialized variables have the numeric value 0 and the string value
|
|---|
| 1011 | \*(FC"\^"\fP
|
|---|
| 1012 | (the null, or empty, string).\*(CX
|
|---|
| 1013 | .EB "\s+2\f(HBCONVERSIONS AND COMPARISONS\*(FR\s0"
|
|---|
| 1014 |
|
|---|
| 1015 | .BT
|
|---|
| 1016 |
|
|---|
| 1017 | .\" --- Historical Features
|
|---|
| 1018 | .ES
|
|---|
| 1019 | .fi
|
|---|
| 1020 | \*(CD1. It is possible to call the \*(FClength()\fP
|
|---|
| 1021 | built-in function not only with no argument, but even without parentheses.
|
|---|
| 1022 | This feature is marked as ``deprecated'' in the POSIX standard, and \*(GK
|
|---|
| 1023 | issues a warning about its use if \*(FC\-\^\-lint\fP
|
|---|
| 1024 | is specified on the command line.
|
|---|
| 1025 | .sp .5
|
|---|
| 1026 | 2. The \*(FCcontinue\fP
|
|---|
| 1027 | and \*(FCbreak\fP statements may be used outside the body of a
|
|---|
| 1028 | \*(FCwhile\*(FR, \*(FCfor\*(FR, or \*(FCdo\fP loop.
|
|---|
| 1029 | Historical AWK implementations have treated such usage as
|
|---|
| 1030 | equivalent to the \*(FCnext\fP statement.
|
|---|
| 1031 | \*(GK supports this usage if \*(FC\-\^\-traditional\fP
|
|---|
| 1032 | is specified.\*(CB
|
|---|
| 1033 | .EB "\s+2\f(HBHISTORICAL FEATURES (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1034 |
|
|---|
| 1035 | .ES
|
|---|
| 1036 | \*(CX
|
|---|
| 1037 | .sp 47
|
|---|
| 1038 | .EB "\s+2\f(HBNOTES\*(FR\s0"
|
|---|
| 1039 |
|
|---|
| 1040 | .BT
|
|---|
| 1041 |
|
|---|
| 1042 | .\" --- Arrays
|
|---|
| 1043 | .ES
|
|---|
| 1044 | .fi
|
|---|
| 1045 | \*(CDAn array subscript is an expression between square brackets
|
|---|
| 1046 | (\*(FC[ \*(FRand \*(FC]\*(FR).
|
|---|
| 1047 | If the expression is a list
|
|---|
| 1048 | (\*(FIexpr\*(FC, \*(FIexpr \*(FR...),
|
|---|
| 1049 | then the subscript is a string consisting of the
|
|---|
| 1050 | concatenation of the (string) value of each expression,
|
|---|
| 1051 | separated by the value of the \*(FCSUBSEP\fP variable.
|
|---|
| 1052 | This simulates multi-dimensional
|
|---|
| 1053 | arrays. For example:
|
|---|
| 1054 | .nf
|
|---|
| 1055 | .sp .5
|
|---|
| 1056 | \*(FCi = "A";\^ j = "B";\^ k = "C"
|
|---|
| 1057 | x[i, j, k] = "hello, world\en"\*(FR
|
|---|
| 1058 | .sp .5
|
|---|
| 1059 | .fi
|
|---|
| 1060 | assigns \*(FC"hello, world\en"\*(FR to the element of the array
|
|---|
| 1061 | \*(FCx\fP
|
|---|
| 1062 | indexed by the string \*(FC"A\e034B\e034C"\*(FR. All arrays in AWK
|
|---|
| 1063 | are associative, i.e., indexed by string values.
|
|---|
| 1064 | .sp .5
|
|---|
| 1065 | Use the special operator \*(FCin\fP in an \*(FCif\fP
|
|---|
| 1066 | or \*(FCwhile\fP statement to see if a particular value is
|
|---|
| 1067 | an array index.
|
|---|
| 1068 | .sp .5
|
|---|
| 1069 | .nf
|
|---|
| 1070 | \*(FCif (val in array)
|
|---|
| 1071 | print array[val]\*(FR
|
|---|
| 1072 | .sp .5
|
|---|
| 1073 | .fi
|
|---|
| 1074 | If the array has multiple subscripts, use
|
|---|
| 1075 | \*(FC(i, j) in array\*(FR.
|
|---|
| 1076 | .sp .5
|
|---|
| 1077 | Use the \*(FCin\fP construct in a \*(FCfor\fP
|
|---|
| 1078 | loop to iterate over all the elements of an array.
|
|---|
| 1079 | .sp .5
|
|---|
| 1080 | Use the \*(FCdelete\fP statement to delete an
|
|---|
| 1081 | element from an array.
|
|---|
| 1082 | \*(CLSpecifying just the array name without a subscript in
|
|---|
| 1083 | the \*(FCdelete\fP
|
|---|
| 1084 | statement deletes the entire contents of an array.\*(CX
|
|---|
| 1085 | .EB "\s+2\f(HBARRAYS\*(FR\s0"
|
|---|
| 1086 |
|
|---|
| 1087 | .\" --- Expressions
|
|---|
| 1088 | .ES
|
|---|
| 1089 | .fi
|
|---|
| 1090 | \*(CDExpressions are used as patterns, for controlling conditional action
|
|---|
| 1091 | statements, and to produce parameter values when calling functions.
|
|---|
| 1092 | Expressions may also be used as simple statements,
|
|---|
| 1093 | particularly if they have side-effects such as assignment.
|
|---|
| 1094 | Expressions mix \*(FIoperands\fP and \*(FIoperators\fP. Operands are
|
|---|
| 1095 | constants, fields, variables, array elements, and the return
|
|---|
| 1096 | values from function calls (both built-in and user-defined).
|
|---|
| 1097 | .sp .5
|
|---|
| 1098 | Regexp constants (\*(FC/\*(FIpat\*(FC/\*(FR), when used as simple expressions,
|
|---|
| 1099 | i.e., not used on the right-hand side of
|
|---|
| 1100 | \*(FC~\fP and \*(FC!~\fP, or as arguments to the
|
|---|
| 1101 | \*(CB\*(FCgensub()\fP,\*(CD
|
|---|
| 1102 | \*(FCgsub()\fP,
|
|---|
| 1103 | \*(FCmatch()\fP,
|
|---|
| 1104 | \*(FCsplit()\fP,
|
|---|
| 1105 | and
|
|---|
| 1106 | \*(FCsub()\fP,
|
|---|
| 1107 | functions, mean \*(FC$0 ~ /\*(FIpat\*(FC/\*(FR.
|
|---|
| 1108 | .sp .5
|
|---|
| 1109 | The AWK operators, in order of decreasing precedence, are:
|
|---|
| 1110 | .sp .5
|
|---|
| 1111 | .fi
|
|---|
| 1112 | .TS
|
|---|
| 1113 | expand;
|
|---|
| 1114 | l lw(1.8i).
|
|---|
| 1115 | \*(FC(\&...)\*(FR grouping
|
|---|
| 1116 | \*(FC$\fP field reference
|
|---|
| 1117 | \*(FC++ \-\^\-\fP T{
|
|---|
| 1118 | increment and decrement,
|
|---|
| 1119 | prefix and postfix
|
|---|
| 1120 | T}
|
|---|
| 1121 | \*(FC^\fP \*(CL\*(FC**\*(FR\*(CD exponentiation
|
|---|
| 1122 | \*(FC+ \- !\fP unary plus, unary minus, and logical negation
|
|---|
| 1123 | \*(FC* / %\fP multiplication, division, and modulus
|
|---|
| 1124 | \*(FC+ \-\fP addition and subtraction
|
|---|
| 1125 | \*(FIspace\fP string concatenation
|
|---|
| 1126 | \*(FC< >\fP less than, greater than
|
|---|
| 1127 | \*(FC<= >=\fP less than or equal, greater than or equal
|
|---|
| 1128 | \*(FC!= ==\fP not equal, equal
|
|---|
| 1129 | \*(FC~ !~\fP regular expression match, negated match
|
|---|
| 1130 | \*(FCin\fP array membership
|
|---|
| 1131 | \*(FC&&\fP logical AND, short circuit
|
|---|
| 1132 | \*(FC||\fP logical OR, short circuit
|
|---|
| 1133 | \*(FC?\^:\fP in-line conditional expression
|
|---|
| 1134 | .T&
|
|---|
| 1135 | l s
|
|---|
| 1136 | l lw(1.8i).
|
|---|
| 1137 | \*(FC=\0+=\0\-=\0*=\0/=\0%=\0^=\0\*(CL**=\*(CD\fP
|
|---|
| 1138 | assignment operators\*(CX
|
|---|
| 1139 | .TE
|
|---|
| 1140 | .EB "\s+2\f(HBEXPRESSIONS\*(FR\s0"
|
|---|
| 1141 |
|
|---|
| 1142 | .BT
|
|---|
| 1143 |
|
|---|
| 1144 | .\" --- Input Control
|
|---|
| 1145 | .ES
|
|---|
| 1146 | .fi
|
|---|
| 1147 | .TS
|
|---|
| 1148 | expand;
|
|---|
| 1149 | l lw(1.8i).
|
|---|
| 1150 | \*(FCgetline\fP T{
|
|---|
| 1151 | set \*(FC$0\fP from next record;
|
|---|
| 1152 | set \*(FCNF\*(FR, \*(FCNR\*(FR, \*(FCFNR\*(FR.
|
|---|
| 1153 | T}
|
|---|
| 1154 | \*(FCgetline < \*(FIfile\*(FR set \*(FC$0\fP from next record of \*(FIfile\*(FR; set \*(FCNF\*(FR.
|
|---|
| 1155 | \*(FCgetline \*(FIv\*(FR T{
|
|---|
| 1156 | set \*(FIv\fP from next input record;
|
|---|
| 1157 | set \*(FCNR\*(FR, \*(FCFNR\*(FR.
|
|---|
| 1158 | T}
|
|---|
| 1159 | \*(FCgetline \*(FIv \*(FC< \*(FIfile\*(FR set \*(FIv\fP from next record of \*(FIfile\*(FR.
|
|---|
| 1160 | \*(FIcmd \*(FC| getline\*(FR pipe into \*(FCgetline\*(FR; set \*(FC$0\*(FR, \*(FCNF\*(FR.
|
|---|
| 1161 | \*(FIcmd \*(FC| getline \*(FIv\*(FR pipe into \*(FCgetline\*(FR; set \*(FIv\*(FR.
|
|---|
| 1162 | \*(CB\*(FIcmd \*(FC|& getline\*(FR co-process pipe into \*(FCgetline\*(FR; set \*(FC$0\*(FR, \*(FCNF\*(FR.
|
|---|
| 1163 | .TE
|
|---|
| 1164 | .fi
|
|---|
| 1165 | .in +.2i
|
|---|
| 1166 | .ti -.2i
|
|---|
| 1167 | \*(FIcmd \*(FC|& getline \*(FIv\*(FR
|
|---|
| 1168 | .br
|
|---|
| 1169 | co-process pipe into \*(FCgetline\*(FR; set \*(FIv\*(FR.
|
|---|
| 1170 | .ti -.2i
|
|---|
| 1171 | \*(FCnext\fP
|
|---|
| 1172 | .br
|
|---|
| 1173 | stop processing the current input
|
|---|
| 1174 | record. Read next input record and
|
|---|
| 1175 | start over with the first pattern in the
|
|---|
| 1176 | program. Upon end of the input data,
|
|---|
| 1177 | execute any \*(FCEND\fP rule(s).
|
|---|
| 1178 | .br
|
|---|
| 1179 | .ti -.2i
|
|---|
| 1180 | \*(CL\*(FCnextfile\fP
|
|---|
| 1181 | .br
|
|---|
| 1182 | stop processing the current input file.
|
|---|
| 1183 | The next input record comes from the
|
|---|
| 1184 | next input file. \*(FCFILENAME\fP \*(CBand
|
|---|
| 1185 | \*(FCARGIND\fP\*(CL are updated, \*(FCFNR\fP is reset to 1,
|
|---|
| 1186 | and processing starts over with the first
|
|---|
| 1187 | pattern in the AWK program. Upon end
|
|---|
| 1188 | of input data, execute any \*(FCEND\fP rule(s).
|
|---|
| 1189 | \*(CREarlier versions of \*(GK used
|
|---|
| 1190 | \*(FCnext file\*(FR, as two words.
|
|---|
| 1191 | This usage is no longer supported.
|
|---|
| 1192 | \*(CR\*(MK does not currently support \*(FCnextfile\*(FR.\*(CD
|
|---|
| 1193 | .in -.2i
|
|---|
| 1194 | .sp .5
|
|---|
| 1195 | .fi
|
|---|
| 1196 | \*(FCgetline\*(FR returns 0 on end of file and \-1 on an error.
|
|---|
| 1197 | \*(CBUpon an error, \*(FCERRNO\*(FR contains a string describing
|
|---|
| 1198 | the problem.\*(CX
|
|---|
| 1199 | .EB "\s+2\f(HBINPUT CONTROL\*(FR\s0"
|
|---|
| 1200 |
|
|---|
| 1201 | .\" --- Output Control
|
|---|
| 1202 | .ES
|
|---|
| 1203 | .fi
|
|---|
| 1204 | .in +.2i
|
|---|
| 1205 | .ti -.2i
|
|---|
| 1206 | \*(CL\*(FCfflush(\*(FR[\*(FIfile\^\*(FR]\*(FC)\*(FR
|
|---|
| 1207 | .br
|
|---|
| 1208 | flush any buffers associated
|
|---|
| 1209 | with the open output file or pipe \*(FIfile\*(FR.\*(CD
|
|---|
| 1210 | \*(CBIf no \*(FIfile\fP, then flush standard output.
|
|---|
| 1211 | If \*(FIfile\fP is null, then flush all open output files and pipes
|
|---|
| 1212 | \*(CR(not \*(NK)\*(CD.
|
|---|
| 1213 | .ti -.2i
|
|---|
| 1214 | \*(FCprint\fP
|
|---|
| 1215 | .br
|
|---|
| 1216 | print the current record. Terminate output record
|
|---|
| 1217 | with \*(FCORS\fP.
|
|---|
| 1218 | .ti -.2i
|
|---|
| 1219 | \*(FCprint \*(FIexpr-list\*(FR
|
|---|
| 1220 | .br
|
|---|
| 1221 | print expressions. Each expression is separated
|
|---|
| 1222 | by the value of \*(FCOFS\fP. Terminate the output record
|
|---|
| 1223 | with \*(FCORS\fP.
|
|---|
| 1224 | .ti -.2i
|
|---|
| 1225 | \*(FCprintf \*(FIfmt\*(FC, \*(FIexpr-list\*(FR
|
|---|
| 1226 | .br
|
|---|
| 1227 | format and print (see \fHPrintf Formats\fP below).
|
|---|
| 1228 | .ti -.2i
|
|---|
| 1229 | \*(FCsystem(\*(FIcmd\*(FC)\*(FR
|
|---|
| 1230 | .br
|
|---|
| 1231 | execute the command \*(FIcmd\*(FR,
|
|---|
| 1232 | and return the exit status
|
|---|
| 1233 | \*(CR(may not be available on non-POSIX systems)\*(CD.
|
|---|
| 1234 | .sp .5
|
|---|
| 1235 | .in -.2i
|
|---|
| 1236 | I/O redirections may be used with both \*(FCprint\fP and \*(FCprintf\fP.
|
|---|
| 1237 | .sp .5
|
|---|
| 1238 | .in +.2i
|
|---|
| 1239 | .ti -.2i
|
|---|
| 1240 | \*(CD\*(FCprint "hello" > \*(FIfile\*(FR
|
|---|
| 1241 | .br
|
|---|
| 1242 | print data to \*(FIfile\fP. The first time the file is written to, it
|
|---|
| 1243 | is truncated. Subsequent commands append data.
|
|---|
| 1244 | .ti -.2i
|
|---|
| 1245 | \*(FCprint "hello" >> \*(FIfile\*(FR
|
|---|
| 1246 | .br
|
|---|
| 1247 | append data to \*(FIfile\fP. The previous contents of \*(FIfile\*(FR are not lost.
|
|---|
| 1248 | .ti -.2i
|
|---|
| 1249 | \*(FCprint "hello" | \*(FIcmd\*(FR
|
|---|
| 1250 | .br
|
|---|
| 1251 | print data down a pipeline to \*(FIcmd\*(FR.
|
|---|
| 1252 | .ti -.2i
|
|---|
| 1253 | \*(CB\*(FCprint "hello" |& \*(FIcmd\*(FR
|
|---|
| 1254 | .br
|
|---|
| 1255 | print data down a pipeline to co-process \*(FIcmd\*(FR.\*(CX
|
|---|
| 1256 | .in -.2i
|
|---|
| 1257 | .EB "\s+2\f(HBOUTPUT CONTROL\*(FR\s0"
|
|---|
| 1258 |
|
|---|
| 1259 | .ES
|
|---|
| 1260 | .fi
|
|---|
| 1261 | .in +.2i
|
|---|
| 1262 | .ti -.2i
|
|---|
| 1263 | \*(CD\*(FCclose(\*(FIfile\*(FC)\*(FR
|
|---|
| 1264 | .br
|
|---|
| 1265 | close input or output file, pipe \*(CBor co-process.\*(CD
|
|---|
| 1266 | .ti -.2i
|
|---|
| 1267 | \*(CB\*(FCclose(\*(FIcommand\*(FC, \*(FIhow\*(FC)\*(FR
|
|---|
| 1268 | .br
|
|---|
| 1269 | close one end of co-process pipe.
|
|---|
| 1270 | Use \*(FC"to"\*(FR for the write end, or
|
|---|
| 1271 | \*(FC"from"\*(FR for the read end.\*(CD
|
|---|
| 1272 | .in -.2i
|
|---|
| 1273 | .sp .5
|
|---|
| 1274 | On success, \*(FCclose()\*(FR returns zero for a file, or the exit status for a process.
|
|---|
| 1275 | It returns \-1 if \*(FIfile\*(FR
|
|---|
| 1276 | was never opened, or
|
|---|
| 1277 | if there was a system problem.
|
|---|
| 1278 | \*(CB\*(FCERRNO\*(FR describes
|
|---|
| 1279 | the error.\*(CX
|
|---|
| 1280 | .EB "\s+2\f(HBCLOSING REDIRECTIONS\*(FR\s0"
|
|---|
| 1281 |
|
|---|
| 1282 | .BT
|
|---|
| 1283 |
|
|---|
| 1284 | .\" --- Printf Formats
|
|---|
| 1285 | .ES
|
|---|
| 1286 | .fi
|
|---|
| 1287 | \*(CDThe \*(FCprintf\fP statement and
|
|---|
| 1288 | \*(FCsprintf()\fP function
|
|---|
| 1289 | accept the following conversion specification formats:
|
|---|
| 1290 | .sp .5
|
|---|
| 1291 | .nf
|
|---|
| 1292 | \*(FC%c\fP an \s-1ASCII\s+1 character
|
|---|
| 1293 | \*(FC%d\fP a decimal number (the integer part)
|
|---|
| 1294 | \*(FC%i\fP a decimal number (the integer part)
|
|---|
| 1295 | \*(FC%e\fP a floating point number of the form
|
|---|
| 1296 | \*(FC[\-]d.dddddde[+\^\-]dd\*(FR
|
|---|
| 1297 | \*(FC%E\fP like \*(FC%e\fP, but use \*(FCE\fP instead of \*(FCe\*(FR
|
|---|
| 1298 | \*(FC%f\fP a floating point number of the form
|
|---|
| 1299 | \*(FC[\-]ddd.dddddd\*(FR
|
|---|
| 1300 | \*(FC%g\fP use \*(FC%e\fP or \*(FC%f\fP, whichever is shorter, with
|
|---|
| 1301 | nonsignificant zeros suppressed
|
|---|
| 1302 | \*(FC%G\fP like \*(FC%g\fP, but use \*(FC%E\fP instead of \*(FC%e\*(FR
|
|---|
| 1303 | \*(FC%o\fP an unsigned octal integer
|
|---|
| 1304 | \*(FC%u\fP an unsigned decimal integer
|
|---|
| 1305 | \*(FC%s\fP a character string
|
|---|
| 1306 | \*(FC%x\fP an unsigned hexadecimal integer
|
|---|
| 1307 | \*(FC%X\fP like \*(FC%x\fP, but use \*(FCABCDEF\fP for 10\(en15
|
|---|
| 1308 | \*(FC%%\fP A literal \*(FC%\fP; no argument is converted
|
|---|
| 1309 | .sp .5
|
|---|
| 1310 | .fi
|
|---|
| 1311 | Optional, additional parameters may lie between the \*(FC%\fP
|
|---|
| 1312 | and the control letter:
|
|---|
| 1313 | .sp .5
|
|---|
| 1314 | .TS
|
|---|
| 1315 | expand;
|
|---|
| 1316 | l lw(2.2i).
|
|---|
| 1317 | \*(CB\*(FIcount\*(FC$\*(FR T{
|
|---|
| 1318 | use the
|
|---|
| 1319 | \*(FIcount\*(FR'th
|
|---|
| 1320 | argument at this point in the formatting
|
|---|
| 1321 | (a \*(FIpositional specifier\*(FR).
|
|---|
| 1322 | Use in translated versions of
|
|---|
| 1323 | format strings, not in the original text of an AWK program.\*(CD
|
|---|
| 1324 | T}
|
|---|
| 1325 | \*(FC\-\fP T{
|
|---|
| 1326 | left-justify the expression within its field.
|
|---|
| 1327 | T}
|
|---|
| 1328 | \*(FIspace\fP T{
|
|---|
| 1329 | for numeric conversions, prefix positive values
|
|---|
| 1330 | with a space and negative values with a
|
|---|
| 1331 | minus sign.
|
|---|
| 1332 | T}
|
|---|
| 1333 | \*(FC+\fP T{
|
|---|
| 1334 | used before the \*(FIwidth\fP modifier means to always
|
|---|
| 1335 | supply a sign for numeric conversions, even if
|
|---|
| 1336 | the data to be formatted is positive. The \*(FC+\fP
|
|---|
| 1337 | overrides the space modifier.
|
|---|
| 1338 | T}
|
|---|
| 1339 | \*(FC#\fP T{
|
|---|
| 1340 | use an ``alternate form'' for some control letters.
|
|---|
| 1341 | T}
|
|---|
| 1342 | \*(FC%o\*(FR T{
|
|---|
| 1343 | supply a leading zero.
|
|---|
| 1344 | T}
|
|---|
| 1345 | \*(FC%x\*(FR, \*(FC%X\*(FR T{
|
|---|
| 1346 | supply a leading \*(FC0x\*(FR or \*(FC0X\*(FR for a nonzero result.
|
|---|
| 1347 | T}
|
|---|
| 1348 | \*(FC%e\*(FR, \*(FC%E\*(FR, \*(FC%f\*(FR T{
|
|---|
| 1349 | the result always has a decimal point.
|
|---|
| 1350 | T}
|
|---|
| 1351 | \*(FC%g\*(FR, \*(FC%G\*(FR T{
|
|---|
| 1352 | trailing zeros are not removed.
|
|---|
| 1353 | T}
|
|---|
| 1354 | \*(FC0\fP T{
|
|---|
| 1355 | a leading zero acts as a flag, indicating output
|
|---|
| 1356 | should be padded with zeros instead of spaces.
|
|---|
| 1357 | This applies even to non-numeric output formats.
|
|---|
| 1358 | Only has an effect when the field width is wider
|
|---|
| 1359 | than the value to be printed.
|
|---|
| 1360 | T}
|
|---|
| 1361 | \*(FIwidth\fP T{
|
|---|
| 1362 | pad the field to this width. The field is normally
|
|---|
| 1363 | padded with spaces. If the \*(FC0\fP flag has been used,
|
|---|
| 1364 | pad with zeros.
|
|---|
| 1365 | T}
|
|---|
| 1366 | \*(FC.\*(FIprec\*(FR T{
|
|---|
| 1367 | precision.
|
|---|
| 1368 | The meaning of the \*(FIprec\*(FR varies by control letter:
|
|---|
| 1369 | T}
|
|---|
| 1370 | \*(FC%d\*(FR, \*(FC%o\*(FR, \*(FC%i\*(FR,
|
|---|
| 1371 | \*(FC%u\*(FR, \*(FC%x\*(FR, \*(FC%X\fP T{
|
|---|
| 1372 | the minimum number of digits to print.
|
|---|
| 1373 | T}
|
|---|
| 1374 | \*(FC%e\*(FR, \*(FC%E\*(FR, \*(FC%f\*(FR T{
|
|---|
| 1375 | the number of digits to print to the right of the decimal point.
|
|---|
| 1376 | T}
|
|---|
| 1377 | \*(FC%g\*(FR, \*(FC%G\fP T{
|
|---|
| 1378 | the maximum number of significant digits.
|
|---|
| 1379 | T}
|
|---|
| 1380 | \*(FC%s\fP T{
|
|---|
| 1381 | the maximum number of characters to print.
|
|---|
| 1382 | T}
|
|---|
| 1383 | .TE
|
|---|
| 1384 | .sp .5
|
|---|
| 1385 | .fi
|
|---|
| 1386 | The dynamic \*(FIwidth\fP and \*(FIprec\fP capabilities of the ANSI C
|
|---|
| 1387 | \*(FCprintf()\fP routines are supported.
|
|---|
| 1388 | A \*(FC*\fP in place of either the \*(FIwidth\fP or \*(FIprec\fP
|
|---|
| 1389 | specifications causes their values to be taken from
|
|---|
| 1390 | the argument list to \*(FCprintf\fP or \*(FCsprintf()\*(FR.
|
|---|
| 1391 | \*(CBUse \*(FC*\*(FIn\*(FC$\*(FR to use positional specifiers
|
|---|
| 1392 | with a dynamic width or precision.\*(CX
|
|---|
| 1393 | .EB "\s+2\f(HBPRINTF FORMATS\*(FR\s0"
|
|---|
| 1394 |
|
|---|
| 1395 |
|
|---|
| 1396 | .BT
|
|---|
| 1397 |
|
|---|
| 1398 | .\" --- Special Filenames
|
|---|
| 1399 | .ES
|
|---|
| 1400 | .fi
|
|---|
| 1401 | \*(CDWhen doing I/O redirection from either \*(FCprint\fP
|
|---|
| 1402 | or \*(FCprintf\fP into a file or via \*(FCgetline\fP
|
|---|
| 1403 | from a file, all three implementations of \*(FCawk\fP
|
|---|
| 1404 | recognize certain special filenames internally. These filenames
|
|---|
| 1405 | allow access to open file descriptors inherited from the
|
|---|
| 1406 | parent process (usually the shell).
|
|---|
| 1407 | These filenames may also be used on the command line to name data files.
|
|---|
| 1408 | The filenames are:
|
|---|
| 1409 | .sp .5
|
|---|
| 1410 | .TS
|
|---|
| 1411 | expand;
|
|---|
| 1412 | l lw(2i).
|
|---|
| 1413 | \*(FC"\-"\fP standard input
|
|---|
| 1414 | \*(FC/dev/stdin\fP standard input \*(CR(not \*(MK)\*(CD
|
|---|
| 1415 | \*(FC/dev/stdout\fP standard output
|
|---|
| 1416 | \*(FC/dev/stderr\fP standard error output
|
|---|
| 1417 | .TE
|
|---|
| 1418 | .sp .5
|
|---|
| 1419 | .fi
|
|---|
| 1420 | \*(CBThe following names are specific to \*(GK.
|
|---|
| 1421 | .sp .5
|
|---|
| 1422 | .in +.2i
|
|---|
| 1423 | .ti -.2i
|
|---|
| 1424 | \*(FC/dev/fd/\^\*(FIn\*(FR
|
|---|
| 1425 | .br
|
|---|
| 1426 | File associated with the open file descriptor \*(FIn\*(FR.
|
|---|
| 1427 | .ti -.2i
|
|---|
| 1428 | \*(FC/inet/tcp/\*(FIlport\*(FC/\*(FIrhost\*(FC/\*(FIrport\*(FR
|
|---|
| 1429 | .br
|
|---|
| 1430 | File for TCP/IP connection on local port \*(FIlport\*(FR to
|
|---|
| 1431 | remote host \*(FIrhost\*(FR on remote port \*(FIrport\*(FR.
|
|---|
| 1432 | Use a port of \*(FC0\*(FR to have the system pick a port.
|
|---|
| 1433 | Usable only with the \*(FC|&\*(FR two-way I/O operator.
|
|---|
| 1434 | .ti -.2i
|
|---|
| 1435 | \*(FC/inet/udp/\*(FIlport\*(FC/\*(FIrhost\*(FC/\*(FIrport\*(FR
|
|---|
| 1436 | .br
|
|---|
| 1437 | Similar, but use UDP/IP instead of TCP/IP.
|
|---|
| 1438 | .ti -.2i
|
|---|
| 1439 | \*(CR\*(FC/inet/raw/\*(FIlport\*(FC/\*(FIrhost\*(FC/\*(FIrport\*(FR
|
|---|
| 1440 | .br
|
|---|
| 1441 | .\" Similar, but use raw IP sockets.
|
|---|
| 1442 | Reserved for future use.\*(CB
|
|---|
| 1443 | .in -.2i
|
|---|
| 1444 | .sp .5
|
|---|
| 1445 | .fi
|
|---|
| 1446 | Other special filenames provide access to information about the running
|
|---|
| 1447 | \*(FCgawk\fP process.
|
|---|
| 1448 | Reading from these files returns a single record.
|
|---|
| 1449 | The filenames and what they return are:\*(FR
|
|---|
| 1450 | .sp .5
|
|---|
| 1451 | .TS
|
|---|
| 1452 | expand;
|
|---|
| 1453 | l lw(2i).
|
|---|
| 1454 | \*(FC/dev/pid\fP process ID of current process
|
|---|
| 1455 | \*(FC/dev/ppid\fP parent process ID of current process
|
|---|
| 1456 | \*(FC/dev/pgrpid\fP process group ID of current process
|
|---|
| 1457 | \*(FC/dev/user\fP T{
|
|---|
| 1458 | .nf
|
|---|
| 1459 | a single newline-terminated record.
|
|---|
| 1460 | The fields are separated with spaces.
|
|---|
| 1461 | \*(FC$1\fP is the return value of \*(FIgetuid\*(FR(2),
|
|---|
| 1462 | \*(FC$2\fP is the return value of \*(FIgeteuid\*(FR(2),
|
|---|
| 1463 | \*(FC$3\fP is the return value of \*(FIgetgid\*(FR(2) , and
|
|---|
| 1464 | \*(FC$4\fP is the return value of \*(FIgetegid\*(FR(2).
|
|---|
| 1465 | .fi
|
|---|
| 1466 | Any additional fields are the group IDs returned
|
|---|
| 1467 | by \*(FIgetgroups\*(FR(2). Multiple groups may not be
|
|---|
| 1468 | supported on all systems.
|
|---|
| 1469 | T}
|
|---|
| 1470 | .TE
|
|---|
| 1471 | .sp .5
|
|---|
| 1472 | .fi
|
|---|
| 1473 | \*(CRThese filenames are now obsolete.
|
|---|
| 1474 | Use the \*(FCPROCINFO\fP array to obtain the information they provide.\*(CL
|
|---|
| 1475 | .EB "\s+2\f(HBSPECIAL FILENAMES\*(FR\s0"
|
|---|
| 1476 | .sp .5
|
|---|
| 1477 | .\" --- Builtin Numeric Functions
|
|---|
| 1478 | .ES
|
|---|
| 1479 | .fi
|
|---|
| 1480 | .TS
|
|---|
| 1481 | expand;
|
|---|
| 1482 | l lw(2i).
|
|---|
| 1483 | \*(CD\*(FCatan2(\*(FIy\*(FC, \*(FIx\*(FC)\*(FR the arctangent of \*(FIy/x\fP in radians.
|
|---|
| 1484 | \*(FCcos(\*(FIexpr\*(FC)\*(FR the cosine of \*(FIexpr\fP, which is in radians.
|
|---|
| 1485 | \*(FCexp(\*(FIexpr\*(FC)\*(FR the exponential function (\*(FIe \*(FC^ \*(FIx\*(FR).
|
|---|
| 1486 | \*(FCint(\*(FIexpr\*(FC)\*(FR truncates to integer.
|
|---|
| 1487 | \*(FClog(\*(FIexpr\*(FC)\*(FR the natural logarithm function (base \*(FIe\^\*(FR).
|
|---|
| 1488 | \*(FCrand()\fP a random number between 0 and 1 (0 \(<= \*(FIN\fP < 1).
|
|---|
| 1489 | \*(FCsin(\*(FIexpr\*(FC)\*(FR the sine of \*(FIexpr\fP, which is in radians.
|
|---|
| 1490 | \*(FCsqrt(\*(FIexpr\*(FC)\*(FR the square root function.
|
|---|
| 1491 | \&\*(FCsrand(\*(FR[\*(FIexpr\^\*(FR]\*(FC)\*(FR T{
|
|---|
| 1492 | uses \*(FIexpr\fP as a new seed for the random number
|
|---|
| 1493 | generator. If no \*(FIexpr\fP, the time of day is used.
|
|---|
| 1494 | Returns previous seed for the random number
|
|---|
| 1495 | generator.\*(CX
|
|---|
| 1496 | T}
|
|---|
| 1497 | .TE
|
|---|
| 1498 | .EB "\s+2\f(HBNUMERIC FUNCTIONS\*(FR\s0"
|
|---|
| 1499 | .sp .5
|
|---|
| 1500 | .\" --- Extensions
|
|---|
| 1501 | .ES
|
|---|
| 1502 | .fi
|
|---|
| 1503 | .in +.2i
|
|---|
| 1504 | .ti -.2i
|
|---|
| 1505 | \*(CD\*(FCextension(\*(FIlib\*(FC, \*(FIfunc\*(FC)\*(FR
|
|---|
| 1506 | .br
|
|---|
| 1507 | dynamically load the shared library
|
|---|
| 1508 | \*(FIlib\*(FR
|
|---|
| 1509 | and call
|
|---|
| 1510 | \*(FIfunc\*(FR
|
|---|
| 1511 | in it to initialize the library.
|
|---|
| 1512 | This adds new built-in functions to \*(GK.
|
|---|
| 1513 | It returns the value returned by
|
|---|
| 1514 | \*(FIfunc\*(FR.\*(CB
|
|---|
| 1515 | .in -.2i
|
|---|
| 1516 | .EB "\s+2\f(HBDYNAMIC EXTENSIONS (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1517 |
|
|---|
| 1518 |
|
|---|
| 1519 | .BT
|
|---|
| 1520 |
|
|---|
| 1521 | .\" --- Builtin String Functions
|
|---|
| 1522 | .ES
|
|---|
| 1523 | .fi
|
|---|
| 1524 | .in +.2i
|
|---|
| 1525 | .ti -.2i
|
|---|
| 1526 | \*(CB\*(FCasort(\*(FIs\*(FC \*(FR[\*(FC, \*(FId\*(FR]\*(FC)\*(FR
|
|---|
| 1527 | .br
|
|---|
| 1528 | sorts the source array \*(FIs\*(FR, replacing the indices with numeric
|
|---|
| 1529 | values 1 through \*(FIn\*(FR (the number of elements in the array),
|
|---|
| 1530 | and returns the number of elements.
|
|---|
| 1531 | If destination \*(FId\*(FR is supplied, \*(FIs\*(FR is copied to \*(FId\*(FR,
|
|---|
| 1532 | \*(FId\*(FR is sorted, and \*(FIs\*(FR is unchanged.\*(CD
|
|---|
| 1533 | .ti -.2i
|
|---|
| 1534 | \*(CB\*(FCasorti(\*(FIs\*(FC \*(FR[\*(FC, \*(FId\*(FR]\*(FC)\*(FR
|
|---|
| 1535 | .br
|
|---|
| 1536 | like \*(FCasort()\*(FR, but sorting is done on the indices, not
|
|---|
| 1537 | the values. The original values are thrown array, so provide a
|
|---|
| 1538 | second array to preserve the first.\*(CD
|
|---|
| 1539 | .ti -.2i
|
|---|
| 1540 | \*(CB\*(FCgensub(\*(FIr\*(FC, \*(FIs\*(FC, \*(FIh \*(FR[\*(FC, \*(FIt\*(FR]\*(FC)\*(FR
|
|---|
| 1541 | .br
|
|---|
| 1542 | search the target string
|
|---|
| 1543 | \*(FIt\fP for matches of the regular expression \*(FIr\*(FR. If
|
|---|
| 1544 | \*(FIh\fP is a string beginning with \*(FCg\fP or \*(FCG\*(FR,
|
|---|
| 1545 | replace all matches of \*(FIr\fP with \*(FIs\*(FR. Otherwise, \*(FIh\fP
|
|---|
| 1546 | is a number indicating which match of \*(FIr\fP to replace.
|
|---|
| 1547 | If \*(FIt\fP is not supplied, \*(FC$0\fP is used instead. Within the
|
|---|
| 1548 | replacement text \*(FIs\*(FR, the sequence \*(FC\e\*(FIn\*(FR,
|
|---|
| 1549 | where \*(FIn\fP is a digit from 1 to 9, may be used to indicate just
|
|---|
| 1550 | the text that matched the \*(FIn\*(FRth parenthesized subexpression.
|
|---|
| 1551 | The sequence \*(FC\e0\fP represents the entire matched text, as does
|
|---|
| 1552 | the character \*(FC&\*(FR. Unlike \*(FCsub()\fP and \*(FCgsub()\*(FR,
|
|---|
| 1553 | the modified string is returned as the result of the function,
|
|---|
| 1554 | and the original target string is \*(FInot\fP changed.\*(CD
|
|---|
| 1555 | .ti -.2i
|
|---|
| 1556 | \*(FCgsub(\*(FIr\*(FC, \*(FIs \*(FR[\*(FC, \*(FIt\*(FR]\*(FC)\*(FR
|
|---|
| 1557 | .br
|
|---|
| 1558 | for each substring matching the
|
|---|
| 1559 | regular expression \*(FIr\fP in the string \*(FIt\*(FR, substitute the
|
|---|
| 1560 | string \*(FIs\*(FR, and return the number of substitutions. If
|
|---|
| 1561 | \*(FIt\fP is not supplied, use \*(FC$0\*(FR. An \*(FC&\fP in the
|
|---|
| 1562 | replacement text is replaced with the text that was actually matched.
|
|---|
| 1563 | Use \*(FC\e&\fP to get a literal \*(FC&\*(FR. See \*(AM
|
|---|
| 1564 | for a fuller discussion of the rules for \*(FC&\*(FR's and backslashes
|
|---|
| 1565 | in the replacement text of \*(CB\*(FCgensub()\*(FR,\*(CD \*(FCsub()\*(FR
|
|---|
| 1566 | and \*(FCgsub()\*(FR
|
|---|
| 1567 | .ti -.2i
|
|---|
| 1568 | \*(FCindex(\*(FIs\*(FC, \*(FIt\*(FC)\*(FR
|
|---|
| 1569 | .br
|
|---|
| 1570 | returns the index of the string
|
|---|
| 1571 | \*(FIt\fP in the string \*(FIs\*(FR, or 0 if \*(FIt\fP is not present.
|
|---|
| 1572 | .ti -.2i
|
|---|
| 1573 | \*(FClength(\*(FR[\*(FIs\*(FR]\*(FC)\*(FR
|
|---|
| 1574 | .br
|
|---|
| 1575 | returns the length of the string
|
|---|
| 1576 | \*(FIs\*(FR, or the length of \*(FC$0\fP if \*(FIs\fP is not supplied.
|
|---|
| 1577 | \*(CBWith an array argument, returns the number of elements
|
|---|
| 1578 | in the array.\*(CD
|
|---|
| 1579 | .ti -.2i
|
|---|
| 1580 | \*(FCmatch(\*(FIs\*(FC, \*(FIr \*(CB\*(FR[\*(FC, \*(FIa\*(FR]\*(CD\*(FC)\*(FR
|
|---|
| 1581 | .br
|
|---|
| 1582 | returns the position in
|
|---|
| 1583 | \*(FIs\fP where the regular expression \*(FIr\fP occurs, or 0 if
|
|---|
| 1584 | \*(FIr\fP is not present, and sets the values of variables
|
|---|
| 1585 | \*(FCRSTART\fP
|
|---|
| 1586 | and \*(FCRLENGTH\*(FR.
|
|---|
| 1587 | \*(CBIf \*(FIa\*(FR is supplied, the text matching all of \*(FIr\*(FR
|
|---|
| 1588 | is placed in \*(FIa\*(FC[0]\*(FR. If there were parenthesized
|
|---|
| 1589 | subexpressions, the matching texts are placed
|
|---|
| 1590 | in \*(FIa\*(FC[1]\*(FR, \*(FIa\*(FC[2]\*(FR, and so on.
|
|---|
| 1591 | Subscripts
|
|---|
| 1592 | \*(FCa[\*(FIn\^\*(FC, "start"]\*(FR,
|
|---|
| 1593 | and
|
|---|
| 1594 | \*(FCa[\*(FIn\^\*(FC, "length"]\*(FR
|
|---|
| 1595 | provide the starting index in the string and length
|
|---|
| 1596 | respectively, of each matching substring.\*(CD
|
|---|
| 1597 | .ti -.2i
|
|---|
| 1598 | \*(FCsplit(\*(FIs\*(FC, \*(FIa \*(FR[\*(FC, \*(FIr\*(FR]\*(FC)\*(FR
|
|---|
| 1599 | .br
|
|---|
| 1600 | splits the string
|
|---|
| 1601 | \*(FIs\fP into the array \*(FIa\fP using the regular expression \*(FIr\*(FR,
|
|---|
| 1602 | and returns the number of fields. If \*(FIr\fP is omitted, \*(FCFS\fP
|
|---|
| 1603 | is used instead. The array \*(FIa\fP is cleared first.
|
|---|
| 1604 | Splitting behaves identically to field splitting.
|
|---|
| 1605 | (See \fHFields\fP, above.)
|
|---|
| 1606 | .ti -.2i
|
|---|
| 1607 | \*(FCsprintf(\*(FIfmt\*(FC, \*(FIexpr-list\*(FC)\*(FR
|
|---|
| 1608 | .br
|
|---|
| 1609 | prints \*(FIexpr-list\fP
|
|---|
| 1610 | according to \*(FIfmt\*(FR, and returns the resulting string.
|
|---|
| 1611 | .ti -.2i
|
|---|
| 1612 | \*(CB\*(FCstrtonum(\*(FIs\*(FC)\*(FR
|
|---|
| 1613 | .br
|
|---|
| 1614 | examines \*(FIs\*(FR, and returns its numeric value.
|
|---|
| 1615 | If \*(FIs\*(FR begins with a leading \*(FC0\*(FR,
|
|---|
| 1616 | \*(FCstrtonum()\*(FR assumes that \*(FIs\*(FR
|
|---|
| 1617 | is an octal number.
|
|---|
| 1618 | If \*(FIs\*(FR begins with a leading \*(FC0x\*(FR
|
|---|
| 1619 | or \*(FC0X\*(FR, \*(FCstrtonum()\*(FR assumes that
|
|---|
| 1620 | \*(FIs\*(FR is a hexadecimal number.\*(CD
|
|---|
| 1621 | .ti -.2i
|
|---|
| 1622 | \*(FCsub(\*(FIr\*(FC, \*(FIs \*(FR[\*(FC, \*(FIt\*(FR]\*(FC)\*(FR
|
|---|
| 1623 | .br
|
|---|
| 1624 | just like
|
|---|
| 1625 | \*(FCgsub()\*(FR, but only the first matching substring is replaced.\*(CX
|
|---|
| 1626 | .in -.2i
|
|---|
| 1627 | .EB "\s+2\f(HBSTRING FUNCTIONS\*(FR\s0"
|
|---|
| 1628 |
|
|---|
| 1629 | .BT
|
|---|
| 1630 |
|
|---|
| 1631 | .\" --- Builtin String Functions
|
|---|
| 1632 | .ES
|
|---|
| 1633 | .fi
|
|---|
| 1634 | .in +.2i
|
|---|
| 1635 | .ti -.2i
|
|---|
| 1636 | \*(CD\*(FCsubstr(\*(FIs\*(FC, \*(FIi \*(FR[\*(FC, \*(FIn\*(FR]\*(FC)\*(FR
|
|---|
| 1637 | .br
|
|---|
| 1638 | returns the at most
|
|---|
| 1639 | \*(FIn\*(FR-character substring of \*(FIs\fP starting at \*(FIi\*(FR.
|
|---|
| 1640 | If \*(FIn\fP is omitted, the rest of \*(FIs\fP is used.
|
|---|
| 1641 | .ti -.2i
|
|---|
| 1642 | \*(FCtolower(\*(FIstr\*(FC)\*(FR
|
|---|
| 1643 | .br
|
|---|
| 1644 | returns a copy of the string \*(FIstr\*(FR,
|
|---|
| 1645 | with all the upper-case characters in \*(FIstr\fP translated to their
|
|---|
| 1646 | corresponding lower-case counterparts. Non-alphabetic characters are
|
|---|
| 1647 | left unchanged.
|
|---|
| 1648 | .ti -.2i
|
|---|
| 1649 | \*(FCtoupper(\*(FIstr\*(FC)\*(FR
|
|---|
| 1650 | .br
|
|---|
| 1651 | returns a copy of the string \*(FIstr\*(FR,
|
|---|
| 1652 | with all the lower-case characters in \*(FIstr\fP translated to their
|
|---|
| 1653 | corresponding upper-case counterparts. Non-alphabetic characters are
|
|---|
| 1654 | left unchanged.\*(CX
|
|---|
| 1655 | .in -.2i
|
|---|
| 1656 | .EB "\s+2\f(HBSTRING FUNCTIONS (continued)\*(FR\s0"
|
|---|
| 1657 |
|
|---|
| 1658 | .\" --- Builtin Time Functions
|
|---|
| 1659 | .ES
|
|---|
| 1660 | .fi
|
|---|
| 1661 | \*(CD\*(GK
|
|---|
| 1662 | provides the following functions for obtaining time stamps and
|
|---|
| 1663 | formatting them.
|
|---|
| 1664 | .sp .5
|
|---|
| 1665 | .fi
|
|---|
| 1666 | .in +.2i
|
|---|
| 1667 | .ti -.2i
|
|---|
| 1668 | \*(FCmktime(\*(FIdatespec\*(FC)\*(FR
|
|---|
| 1669 | .br
|
|---|
| 1670 | turns \*(FIdatespec\fP into a time
|
|---|
| 1671 | stamp of the same form as returned by \*(FCsystime()\*(FR.
|
|---|
| 1672 | The \*(FIdatespec\fP is a string of the form
|
|---|
| 1673 | \*(FC"\*(FIYYYY MM DD HH MM SS[ DST]\*(FC"\*(FR.
|
|---|
| 1674 | .ti -.2i
|
|---|
| 1675 | \*(FCstrftime(\*(FR[\*(FIformat \*(FR[\*(FC, \*(FItimestamp\*(FR]]\*(FC)\*(FR
|
|---|
| 1676 | .br
|
|---|
| 1677 | formats \*(FItimestamp\fP
|
|---|
| 1678 | according to the specification in \*(FIformat\*(FR. The
|
|---|
| 1679 | \*(FItimestamp\fP should be of the same form as returned by
|
|---|
| 1680 | \*(FCsystime()\*(FR.
|
|---|
| 1681 | If \*(FItimestamp\fP is missing, the current time of day is used. If
|
|---|
| 1682 | \*(FIformat\fP is missing, a default format equivalent to the output
|
|---|
| 1683 | of \*(FIdate\*(FR(1) is used.
|
|---|
| 1684 | .ti -.2i
|
|---|
| 1685 | \*(FCsystime()\fP
|
|---|
| 1686 | .br
|
|---|
| 1687 | returns the current time of day as the number of
|
|---|
| 1688 | seconds since the Epoch.\*(CB
|
|---|
| 1689 | .in -.2i
|
|---|
| 1690 | .EB "\s+2\f(HBTIME FUNCTIONS (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1691 |
|
|---|
| 1692 | .\" --- Builtin Bit Manipulation Functions
|
|---|
| 1693 | .ES
|
|---|
| 1694 | .fi
|
|---|
| 1695 | \*(CD\*(GK
|
|---|
| 1696 | provides the following functions for doing bitwise operations.
|
|---|
| 1697 | .sp .5
|
|---|
| 1698 | .fi
|
|---|
| 1699 | .in +.2i
|
|---|
| 1700 | .ti -.2i
|
|---|
| 1701 | \*(FCand(\*(FIv1\*(FC, \*(FIv2\*(FC)\*(FR
|
|---|
| 1702 | .br
|
|---|
| 1703 | returns the bitwise AND of the values provided by
|
|---|
| 1704 | \*(FIv1\*(FR and \*(FIv2\*(FR.
|
|---|
| 1705 | .ti -.2i
|
|---|
| 1706 | \*(FCcompl(\*(FIval\*(FC)\*(FR
|
|---|
| 1707 | .br
|
|---|
| 1708 | returns the bitwise complement of
|
|---|
| 1709 | \*(FIval\*(FR.
|
|---|
| 1710 | .ti -.2i
|
|---|
| 1711 | \*(FClshift(\*(FIval\*(FC, \*(FIcount\*(FC)\*(FR
|
|---|
| 1712 | .br
|
|---|
| 1713 | returns the value of \*(FIval\*(FR,
|
|---|
| 1714 | shifted left by \*(FIcount\*(FR bits.
|
|---|
| 1715 | .ti -.2i
|
|---|
| 1716 | \*(FCor(\*(FIv1\*(FC, \*(FIv2\*(FC)\*(FR
|
|---|
| 1717 | .br
|
|---|
| 1718 | returns the bitwise OR of the values provided by
|
|---|
| 1719 | \*(FIv1\*(FR and \*(FIv2\*(FR.
|
|---|
| 1720 | .ti -.2i
|
|---|
| 1721 | \*(FCrshift(\*(FIval\*(FC, \*(FIcount\*(FC)\*(FR
|
|---|
| 1722 | .br
|
|---|
| 1723 | returns the value of \*(FIval\*(FR,
|
|---|
| 1724 | shifted right by \*(FIcount\*(FR bits.
|
|---|
| 1725 | .ti -.2i
|
|---|
| 1726 | \*(FCxor(\*(FIv1\*(FC, \*(FIv2\*(FC)\*(FR
|
|---|
| 1727 | .br
|
|---|
| 1728 | teturns the bitwise XOR of the values provided by
|
|---|
| 1729 | \*(FIv1\*(FR and \*(FIv2\*(FR.\*(CB
|
|---|
| 1730 | .in -.2i
|
|---|
| 1731 | .EB "\s+2\f(HBBIT MANIPULATION FUNCTIONS (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1732 |
|
|---|
| 1733 | .\" --- Environment Variables
|
|---|
| 1734 | .ES
|
|---|
| 1735 | .fi
|
|---|
| 1736 | \*(CDThe environment variable \*(FCAWKPATH\fP specifies a search path to use
|
|---|
| 1737 | when finding source files named with the \*(FC\-f\fP
|
|---|
| 1738 | option.
|
|---|
| 1739 | The default path is
|
|---|
| 1740 | \*(FC".:/usr/local/share/awk"\*(FR.
|
|---|
| 1741 | .\" if this variable does not exist.
|
|---|
| 1742 | .\" (The actual directory may vary,
|
|---|
| 1743 | .\" depending upon how \*(GK was built and installed.)
|
|---|
| 1744 | If a file name given to the \*(FC\-f\fP option contains a ``/'' character,
|
|---|
| 1745 | no path search is performed.
|
|---|
| 1746 | .sp .5
|
|---|
| 1747 | If \*(FCPOSIXLY_CORRECT\fP exists
|
|---|
| 1748 | .\" in the environment,
|
|---|
| 1749 | then \*(GK
|
|---|
| 1750 | behaves exactly as if the \*(FC\-\^\-posix\fP option had been given.\*(CB
|
|---|
| 1751 | .EB "\s+2\f(HBENVIRONMENT VARIABLES (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1752 |
|
|---|
| 1753 | .BT
|
|---|
| 1754 |
|
|---|
| 1755 | .\" --- User-defined Functions
|
|---|
| 1756 | .ES
|
|---|
| 1757 | .fi
|
|---|
| 1758 | \*(CDFunctions in AWK are defined as follows:
|
|---|
| 1759 | .sp .5
|
|---|
| 1760 | .nf
|
|---|
| 1761 | \*(FCfunction \*(FIname\*(FC(\*(FIparameter list\*(FC)
|
|---|
| 1762 | {
|
|---|
| 1763 | \*(FIstatements
|
|---|
| 1764 | \*(FC}\*(FR
|
|---|
| 1765 | .sp .5
|
|---|
| 1766 | .fi
|
|---|
| 1767 | Functions are executed when they are called from within expressions
|
|---|
| 1768 | in either patterns or actions. Actual parameters supplied in the function
|
|---|
| 1769 | call instantiate the formal parameters declared in the function.
|
|---|
| 1770 | Arrays are passed by reference, other variables are passed by value.
|
|---|
| 1771 | .sp .5
|
|---|
| 1772 | Local variables are declared as extra parameters
|
|---|
| 1773 | in the parameter list. The convention is to separate local variables from
|
|---|
| 1774 | real parameters by extra spaces in the parameter list. For example:
|
|---|
| 1775 | .sp .5
|
|---|
| 1776 | .nf
|
|---|
| 1777 | \*(FC# a and b are local
|
|---|
| 1778 | function f(p, q, a, b)
|
|---|
| 1779 | {
|
|---|
| 1780 | \&.....
|
|---|
| 1781 | }
|
|---|
| 1782 | .sp .3
|
|---|
| 1783 | /abc/ { ... ; f(1, 2) ; ... }\*(FR
|
|---|
| 1784 | .fi
|
|---|
| 1785 | .sp .5
|
|---|
| 1786 | The left parenthesis in a function call is required
|
|---|
| 1787 | to immediately follow the function name
|
|---|
| 1788 | without any intervening white space.
|
|---|
| 1789 | This is to avoid a syntactic ambiguity with the concatenation operator.
|
|---|
| 1790 | This restriction does not apply to the built-in functions.
|
|---|
| 1791 | .sp .5
|
|---|
| 1792 | Functions may call each other and may be recursive.
|
|---|
| 1793 | Function parameters used as local variables are initialized
|
|---|
| 1794 | to the null string and the number zero upon function invocation.
|
|---|
| 1795 | .sp .5
|
|---|
| 1796 | Use \*(FCreturn\fP to return a value from a function. The return value
|
|---|
| 1797 | is undefined if no value is provided, or if the function returns by
|
|---|
| 1798 | ``falling off'' the end.
|
|---|
| 1799 | .sp .5
|
|---|
| 1800 | \*(CLThe word
|
|---|
| 1801 | \*(FCfunc\fP
|
|---|
| 1802 | may be used in place of
|
|---|
| 1803 | \*(FCfunction\*(FR.
|
|---|
| 1804 | \*(CRNote: This usage is deprecated.\*(CX
|
|---|
| 1805 | .EB "\s+2\f(HBUSER-DEFINED FUNCTIONS\*(FR\s0"
|
|---|
| 1806 |
|
|---|
| 1807 | .\" --- Localization
|
|---|
| 1808 | .ES
|
|---|
| 1809 | .fi
|
|---|
| 1810 | \*(CDThere are several steps involved in producing and running a localizable
|
|---|
| 1811 | \*(AK program.
|
|---|
| 1812 | .sp .5
|
|---|
| 1813 | 1. Add a \*(FCBEGIN\*(FR action to assign a value to the
|
|---|
| 1814 | \*(FCTEXTDOMAIN\*(FR variable to set the text domain for
|
|---|
| 1815 | your program.
|
|---|
| 1816 | .sp .5
|
|---|
| 1817 | .ti +5n
|
|---|
| 1818 | \*(FCBEGIN { TEXTDOMAIN = "myprog" }\*(FR
|
|---|
| 1819 | .sp .5
|
|---|
| 1820 | This allows \*(GK to find the \*(FC\&.mo\*(FR
|
|---|
| 1821 | file associated with your program.
|
|---|
| 1822 | Without this step, \*(GK uses the \*(FCmessages\*(FR text domain,
|
|---|
| 1823 | which probably won't work.
|
|---|
| 1824 | .sp .5
|
|---|
| 1825 | 2. Mark all strings that should be translated with leading underscores.
|
|---|
| 1826 | .sp .5
|
|---|
| 1827 | 3. Use the
|
|---|
| 1828 | \*(FCbindtextdomain()\*(FR,
|
|---|
| 1829 | \*(FCdcgettext()\*(FR,
|
|---|
| 1830 | and/or
|
|---|
| 1831 | \*(FCdcngettext()\*(FR
|
|---|
| 1832 | functions in your program, as appropriate.
|
|---|
| 1833 | .sp .5
|
|---|
| 1834 | 4. Run
|
|---|
| 1835 | .sp .5
|
|---|
| 1836 | .ti +5n
|
|---|
| 1837 | \*(FCgawk \-\^\-gen\-po \-f myprog.awk > myprog.po\*(FR
|
|---|
| 1838 | .sp .5
|
|---|
| 1839 | to generate a \*(FC\&.po\*(FR
|
|---|
| 1840 | file for your program.
|
|---|
| 1841 | .sp .5
|
|---|
| 1842 | 5. Provide appropriate translations, and build and install a corresponding
|
|---|
| 1843 | \*(FC\&.mo\*(FR file.
|
|---|
| 1844 | .sp .5
|
|---|
| 1845 | The internationalization features are described in full detail in \*(AM.\*(CB
|
|---|
| 1846 | .EB "\s+2\f(HBLOCALIZATION (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1847 |
|
|---|
| 1848 |
|
|---|
| 1849 | .BT
|
|---|
| 1850 |
|
|---|
| 1851 | .\" --- Builtin Internationalization Functions
|
|---|
| 1852 | .ES
|
|---|
| 1853 | .fi
|
|---|
| 1854 | \*(CD\*(GK
|
|---|
| 1855 | provides the following functions for runtime message translation.
|
|---|
| 1856 | .in +.2i
|
|---|
| 1857 | .sp .5
|
|---|
| 1858 | .ti -.2i
|
|---|
| 1859 | \*(FCbindtextdomain(\*(FIdirectory \*(FR[\*(FC, \*(FIdomain\*(FR]\*(FC)\*(FR
|
|---|
| 1860 | .br
|
|---|
| 1861 | specifies the directory where \*(GK looks for the \*(FC\&.mo\*(FR
|
|---|
| 1862 | files, in case they
|
|---|
| 1863 | will not or cannot be placed in the ``standard'' locations
|
|---|
| 1864 | (e.g., during testing.)
|
|---|
| 1865 | It returns the directory where \*(FIdomain\*(FR is ``bound.''
|
|---|
| 1866 | .sp .5
|
|---|
| 1867 | The default \*(FIdomain\*(FR is the value of \*(FCTEXTDOMAIN\*(FR.
|
|---|
| 1868 | When \*(FIdirectory\*(FR is the null string (\*(FC"\^"\*(FR),
|
|---|
| 1869 | \*(FCbindtextdomain()\*(FR returns the current binding for the
|
|---|
| 1870 | given \*(FIdomain\*(FR.
|
|---|
| 1871 | .ti -.2i
|
|---|
| 1872 | \*(FCdcgettext(\*(FIstring \*(FR[\*(FC, \*(FIdomain \*(FR[\*(FC, \*(FIcategory\*(FR]]\*(FC)\*(FR
|
|---|
| 1873 | .br
|
|---|
| 1874 | returns the translation of \*(FIstring\*(FR in text domain
|
|---|
| 1875 | \*(FIdomain\*(FR for locale category \*(FIcategory\*(FR.
|
|---|
| 1876 | The default value for \*(FIdomain\*(FR is the current value of \*(FCTEXTDOMAIN\*(FR.
|
|---|
| 1877 | The default value for \*(FIcategory\*(FR is \*(FC"LC_MESSAGES"\*(FR.
|
|---|
| 1878 | .sp .5
|
|---|
| 1879 | If you supply a value for \*(FIcategory\*(FR, it must be a string equal to
|
|---|
| 1880 | one of the known locale categories.
|
|---|
| 1881 | You must also supply a text domain. Use \*(FCTEXTDOMAIN\*(FR
|
|---|
| 1882 | to use the current domain.
|
|---|
| 1883 | .ti -.2i
|
|---|
| 1884 | \*(FCdcngettext(\*(FIstring1\*(FC, \*(FIstring2\*(FC, \*(FInumber\*(FR [\*(FC, \*(FIdom \*(FR[\*(FC, \*(FIcat\*(FR]]\*(FC)\*(FR
|
|---|
| 1885 | .br
|
|---|
| 1886 | returns the plural form used for \*(FInumber\*(FR of the translation of
|
|---|
| 1887 | \*(FIstring1\*(FR and \*(FIstring2\*(FR in text domain
|
|---|
| 1888 | \*(FIdom\*(FR for locale category \*(FIcat\*(FR.
|
|---|
| 1889 | The default value for \*(FIdom\*(FR is the current value of \*(FCTEXTDOMAIN\*(FR.
|
|---|
| 1890 | \*(FC"LC_MESSAGES"\*(FR
|
|---|
| 1891 | is the default value for \*(FIcat\*(FR.
|
|---|
| 1892 | .sp .5
|
|---|
| 1893 | If you supply a value for \*(FIcat\*(FR, it must be a string equal to
|
|---|
| 1894 | one of the known locale categories.
|
|---|
| 1895 | You must also supply a text domain. Use \*(FCTEXTDOMAIN\*(FR
|
|---|
| 1896 | to use the current domain.\*(CB
|
|---|
| 1897 | .in -.2i
|
|---|
| 1898 | .EB "\s+2\f(HBINTERNATIONALIZATION (\*(GK\f(HB)\*(FR\s0"
|
|---|
| 1899 |
|
|---|
| 1900 |
|
|---|
| 1901 | .\" --- FTP/HTTP Information
|
|---|
| 1902 | .ES
|
|---|
| 1903 | .nf
|
|---|
| 1904 | \*(CDHost: \*(FCftp.gnu.org\*(FR
|
|---|
| 1905 | File: \*(FC/gnu/gawk/gawk-3.1.5.tar.gz\fP
|
|---|
| 1906 | .in +.2i
|
|---|
| 1907 | .fi
|
|---|
| 1908 | GNU \*(AK (\*(GK). There may be a later version.
|
|---|
| 1909 | .in -.2i
|
|---|
| 1910 | .nf
|
|---|
| 1911 | .sp .5
|
|---|
| 1912 | \*(FChttp://cm.bell-labs.com/who/bwk/awk.tar.gz\fP
|
|---|
| 1913 | .in +.2i
|
|---|
| 1914 | .fi
|
|---|
| 1915 | \*(NK. This version requires an ANSI C compiler;
|
|---|
| 1916 | GCC (the GNU Compiler Collection) works well.
|
|---|
| 1917 | .in -.2i
|
|---|
| 1918 | .nf
|
|---|
| 1919 | .sp .5
|
|---|
| 1920 | Host: \*(FCftp.whidbey.net\*(FR
|
|---|
| 1921 | File: \*(FC/pub/brennan/mawk1.3.3.tar.gz\fP
|
|---|
| 1922 | .in +.2i
|
|---|
| 1923 | .fi
|
|---|
| 1924 | Michael Brennan's \*(MK. There may be a newer version.\*(CX
|
|---|
| 1925 | .in -.2i
|
|---|
| 1926 | .EB "\s+2\f(HBFTP/HTTP INFORMATION\*(FR\s0"
|
|---|
| 1927 |
|
|---|
| 1928 |
|
|---|
| 1929 | .\" --- Copying Permissions
|
|---|
| 1930 | .ES
|
|---|
| 1931 | .fi
|
|---|
| 1932 | \*(CDCopyright \(co 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
|
|---|
| 1933 | Free Software Foundation, Inc.
|
|---|
| 1934 | .sp .5
|
|---|
| 1935 | Permission is granted to make and distribute verbatim copies of this
|
|---|
| 1936 | reference card provided the copyright notice and this permission notice
|
|---|
| 1937 | are preserved on all copies.
|
|---|
| 1938 | .sp .5
|
|---|
| 1939 | Permission is granted to copy and distribute modified versions of this
|
|---|
| 1940 | reference card under the conditions for verbatim copying, provided that
|
|---|
| 1941 | the entire resulting derived work is distributed under the terms of a
|
|---|
| 1942 | permission notice identical to this one.
|
|---|
| 1943 | .sp .5
|
|---|
| 1944 | Permission is granted to copy and distribute translations of this
|
|---|
| 1945 | reference card into another language, under the above conditions for
|
|---|
| 1946 | modified versions, except that this permission notice may be stated in a
|
|---|
| 1947 | translation approved by the Foundation.\*(CX
|
|---|
| 1948 | .EB "\s+2\f(HBCOPYING PERMISSIONS\*(FR\s0"
|
|---|
| 1949 | .BT
|
|---|