GAWK(1) Utility Commands GAWK(1)
NAME
gawk - pattern scanning and processing language
SYNOPSIS
gawk [ POSIX or GNU style options ] -f program-file [ --
] file ...
gawk [ POSIX or GNU style options ] [ -- ] program-text
file ...
pgawk [ POSIX or GNU style options ] -f program-file [
-- ] file ...
pgawk [ POSIX or GNU style options ] [ -- ] program-text
file ...
DESCRIPTION
Gawk is the GNU Project's implementation of the AWK pro-
gramming language. It conforms to the definition of the
language in the POSIX 1003.1 Standard. This version in
turn is based on the description in The AWK Programming
Language, by Aho, Kernighan, and Weinberger, with the
additional features found in the System V Release 4 ver-
sion of UNIX awk. Gawk also provides more recent Bell
Laboratories awk extensions, and a number of GNU-spe-
cific extensions.
Pgawk is the profiling version of gawk. It is identical
in every way to gawk, except that programs run more
slowly, and it automatically produces an execution pro-
file in the file awkprof.out when done. See the --pro-
file option, below.
The command line consists of options to gawk itself, the
AWK program text (if not supplied via the -f or --file
options), and values to be made available in the ARGC
and ARGV pre-defined AWK variables.
OPTION FORMAT
Gawk options may be either traditional POSIX one letter
options, or GNU-style long options. POSIX options start
with a single "-", while long options start with "--".
Long options are provided for both GNU-specific features
and for POSIX-mandated features.
Following the POSIX standard, gawk-specific options are
supplied via arguments to the -W option. Multiple -W
options may be supplied Each -W option has a correspond-
ing long option, as detailed below. Arguments to long
options are either joined with the option by an = sign,
with no intervening spaces, or they may be provided in
the next command line argument. Long options may be
abbreviated, as long as the abbreviation remains unique.
OPTIONS
Gawk accepts the following options, listed by frequency.
-F fs
--field-separator fs
Use fs for the input field separator (the value
of the FS predefined variable).
-v var=val
--assign var=val
Assign the value val to the variable var, before
execution of the program begins. Such variable
values are available to the BEGIN block of an AWK
program.
-f program-file
--file program-file
Read the AWK program source from the file pro-
gram-file, instead of from the first command line
argument. Multiple -f (or --file) options may be
used.
-mf NNN
-mr NNN
Set various memory limits to the value NNN. The
f flag sets the maximum number of fields, and the
r flag sets the maximum record size. These two
flags and the -m option are from an earlier ver-
sion of the Bell Laboratories research version of
UNIX awk. They are ignored by gawk, since gawk
has no pre-defined limits.
-W compat
-W traditional
--compat
--traditional
Run in compatibility mode. In compatibility
mode, gawk behaves identically to UNIX awk; none
of the GNU-specific extensions are recognized.
The use of --traditional is preferred over the
other forms of this option. See GNU EXTENSIONS,
below, for more information.
-W copyleft
-W copyright
--copyleft
--copyright
Print the short version of the GNU copyright
information message on the standard output and
exit successfully.
-W dump-variables[=file]
--dump-variables[=file]
Print a sorted list of global variables, their
types and final values to file. If no file is
provided, gawk uses a file named awkvars.out in
the current directory.
Having a list of all the global variables is a
good way to look for typographical errors in your
programs. You would also use this option if you
have a large program with a lot of functions, and
you want to be sure that your functions don't
inadvertently use global variables that you meant
to be local. (This is a particularly easy mis-
take to make with simple variable names like i,
j, and so on.)
-W exec file
--exec file
Similar to -f, however, this is option is the
last one processed. This should be used with #!
scripts, particularly for CGI applications, to
avoid passing in options or source code (!) on
the command line from a URL. This option dis-
ables command-line variable assignments.
-W gen-po
--gen-po
Scan and parse the AWK program, and generate a
GNU .po format file on standard output with
entries for all localizable strings in the pro-
gram. The program itself is not executed. See
the GNU gettext distribution for more information
on .po files.
-W help
-W usage
--help
--usage
Print a relatively short summary of the available
options on the standard output. (Per the GNU
Coding Standards, these options cause an immedi-
ate, successful exit.)
-W lint[=value]
--lint[=value]
Provide warnings about constructs that are dubi-
ous or non-portable to other AWK implementations.
With an optional argument of fatal, lint warnings
become fatal errors. This may be drastic, but
its use will certainly encourage the development
of cleaner AWK programs. With an optional argu-
ment of invalid, only warnings about things that
are actually invalid are issued. (This is not
fully implemented yet.)
-W lint-old
--lint-old
Provide warnings about constructs that are not
portable to the original version of Unix awk.
-W non-decimal-data
--non-decimal-data
Recognize octal and hexadecimal values in input
data. Use this option with great caution!
-W posix
--posix
This turns on compatibility mode, with the fol-
lowing additional restrictions:
· \x escape sequences are not recognized.
· Only space and tab act as field separators when
FS is set to a single space, newline does not.
· You cannot continue lines after ? and :.
· The synonym func for the keyword function is
not recognized.
· The operators ** and **= cannot be used in
place of ^ and ^=.
· The fflush() function is not available.
-W profile[=prof_file]
--profile[=prof_file]
Send profiling data to prof_file. The default is
awkprof.out. When run with gawk, the profile is
just a "pretty printed" version of the program.
- 1
- 2
- 3
前往页