DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(gawk) Options

Info Catalog (gawk) Invoking Gawk (gawk) Invoking Gawk (gawk) Other Arguments
 
 Command Line Options
 ====================
 
    Options begin with a dash, and consist of a single character.  GNU
 style long options consist of two dashes and a keyword.  The keyword
 can be abbreviated, as long the abbreviation allows the option to be
 uniquely identified.  If the option takes an argument, then the keyword
 is either immediately followed by an equals sign (`=') and the
 argument's value, or the keyword and the argument's value are separated
 by whitespace.  For brevity, the discussion below only refers to the
 traditional short options; however the long and short options are
 interchangeable in all contexts.
 
    Each long option for `gawk' has a corresponding POSIX-style option.
 The options and their meanings are as follows:
 
 `-F FS'
 `--field-separator FS'
      Sets the `FS' variable to FS ( Specifying How Fields are
      Separated Field Separators.).
 
 `-f SOURCE-FILE'
 `--file SOURCE-FILE'
      Indicates that the `awk' program is to be found in SOURCE-FILE
      instead of in the first non-option argument.
 
 `-v VAR=VAL'
 `--assign VAR=VAL'
      Sets the variable VAR to the value VAL *before* execution of the
      program begins.  Such variable values are available inside the
      `BEGIN' rule ( Other Command Line Arguments Other
      Arguments.).
 
      The `-v' option can only set one variable, but you can use it more
      than once, setting another variable each time, like this: `awk
      -v foo=1 -v bar=2 ...'.
 
      *Caution:*  Using `-v' to set the values of the builtin variables
      may lead to suprising results.  `awk' will reset the values of
      those variables as it needs to, possibly ignoring any predefined
      value you may have given.
 
 `-mf NNN'
 `-mr NNN'
      Set various memory limits to the value NNN.  The `f' flag sets the
      maximum number of fields, and the `r' flag sets the maximum record
      size.  These two flags and the `-m' option are from the Bell Labs
      research version of Unix `awk'.  They are provided for
      compatibility, but otherwise ignored by `gawk', since `gawk' has
      no predefined limits.
 
 `-W GAWK-OPT'
      Following the POSIX standard, options that are implementation
      specific are supplied as arguments to the `-W' option.  These
      options also have corresponding GNU style long options.  See below.
 
 `--'
      Signals the end of the command line options.  The following
      arguments are not treated as options even if they begin with `-'.
      This interpretation of `--' follows the POSIX argument parsing
      conventions.
 
      This is useful if you have file names that start with `-', or in
      shell scripts, if you have file names that will be specified by
      the user which could start with `-'.
 
    The following `gawk'-specific options are available:
 
 `-W traditional'
 `-W compat'
 `--traditional'
 `--compat'
      Specifies "compatibility mode", in which the GNU extensions to the
      `awk' language are disabled, so that `gawk' behaves just like the
      Bell Labs research version of Unix `awk'.  `--traditional' is the
      preferred form of this option.   Extensions in `gawk' Not in
      POSIX `awk' POSIX/GNU, which summarizes the extensions.  Also see
       Downward Compatibility and Debugging Compatibility Mode.
 
 `-W copyleft'
 `-W copyright'
 `--copyleft'
 `--copyright'
      Print the short version of the General Public License, and then
      exit.  This option may disappear in a future version of `gawk'.
 
 `-W help'
 `-W usage'
 `--help'
 `--usage'
      Print a "usage" message summarizing the short and long style
      options that `gawk' accepts, and then exit.
 
 `-W lint'
 `--lint'
      Warn about constructs that are dubious or non-portable to other
      `awk' implementations.  Some warnings are issued when `gawk' first
      reads your program.  Others are issued at run-time, as your
      program executes.
 
 `-W lint-old'
 `--lint-old'
      Warn about constructs that are not available in the original
      Version 7 Unix version of `awk' ( Major Changes between V7
      and SVR3.1 V7/SVR3.1.).
 
 `-W posix'
 `--posix'
      Operate in strict POSIX mode.  This disables all `gawk' extensions
      (just like `--traditional'), and adds the following additional
      restrictions:
 
         * `\x' escape sequences are not recognized ( Escape
           Sequences).
 
         * Newlines do not act as whitespace to separate fields when
           `FS' is equal to a single space.
 
         * The synonym `func' for the keyword `function' is not
           recognized ( Function Definition Syntax Definition
           Syntax.).
 
         * The operators `**' and `**=' cannot be used in place of `^'
           and `^=' ( Arithmetic Operators Arithmetic Ops., and
           also  Assignment Expressions Assignment Ops.).
 
         * Specifying `-Ft' on the command line does not set the value
           of `FS' to be a single tab character ( Specifying How
           Fields are Separated Field Separators.).
 
         * The `fflush' built-in function is not supported (
           Built-in Functions for Input/Output I/O Functions.).
 
      If you supply both `--traditional' and `--posix' on the command
      line, `--posix' will take precedence. `gawk' will also issue a
      warning if both options are supplied.
 
 `-W re-interval'
 `--re-interval'
      Allow interval expressions ( Regular Expression Operators
      Regexp Operators.), in regexps.  Because interval expressions were
      traditionally not available in `awk', `gawk' does not provide them
      by default. This prevents old `awk' programs from breaking.
 
 `-W source PROGRAM-TEXT'
 `--source PROGRAM-TEXT'
      Program source code is taken from the PROGRAM-TEXT.  This option
      allows you to mix source code in files with source code that you
      enter on the command line. This is particularly useful when you
      have library functions that you wish to use from your command line
      programs ( The `AWKPATH' Environment Variable AWKPATH
      Variable.).
 
 `-W version'
 `--version'
      Prints version information for this particular copy of `gawk'.
      This allows you to determine if your copy of `gawk' is up to date
      with respect to whatever the Free Software Foundation is currently
      distributing.  It is also useful for bug reports ( Reporting
      Problems and Bugs Bugs.).
 
    Any other options are flagged as invalid with a warning message, but
 are otherwise ignored.
 
    In compatibility mode, as a special case, if the value of FS supplied
 to the `-F' option is `t', then `FS' is set to the tab character
 (`"\t"').  This is only true for `--traditional', and not for `--posix'
 ( Specifying How Fields are Separated Field Separators.).
 
    The `-f' option may be used more than once on the command line.  If
 it is, `awk' reads its program source from all of the named files, as
 if they had been concatenated together into one big file.  This is
 useful for creating libraries of `awk' functions.  Useful functions can
 be written once, and then retrieved from a standard place, instead of
 having to be included into each individual program.
 
    You can type in a program at the terminal and still use library
 functions, by specifying `-f /dev/tty'.  `awk' will read a file from
 the terminal to use as part of the `awk' program.  After typing your
 program, type `Control-d' (the end-of-file character) to terminate it.
 (You may also use `-f -' to read program source from the standard
 input, but then you will not be able to also use the standard input as a
 source of data.)
 
    Because it is clumsy using the standard `awk' mechanisms to mix
 source file and command line `awk' programs, `gawk' provides the
 `--source' option.  This does not require you to pre-empt the standard
 input for your source code, and allows you to easily mix command line
 and library source code ( The `AWKPATH' Environment Variable
 AWKPATH Variable.).
 
    If no `-f' or `--source' option is specified, then `gawk' will use
 the first non-option command line argument as the text of the program
 source code.
 
    If the environment variable `POSIXLY_CORRECT' exists, then `gawk'
 will behave in strict POSIX mode, exactly as if you had supplied the
 `--posix' command line option.  Many GNU programs look for this
 environment variable to turn on strict POSIX mode. If you supply
 `--lint' on the command line, and `gawk' turns on POSIX mode because of
 `POSIXLY_CORRECT', then it will print a warning message indicating that
 POSIX mode is in effect.
 
    You would typically set this variable in your shell's startup file.
 For a Bourne compatible shell (such as Bash), you would add these lines
 to the `.profile' file in your home directory.
 
      POSIXLY_CORRECT=true
      export POSIXLY_CORRECT
 
    For a `csh' compatible shell,(1) you would add this line to the
 `.login' file in your home directory.
 
      setenv POSIXLY_CORRECT true
 
    ---------- Footnotes ----------
 
    (1) Not recommended.
 
Info Catalog (gawk) Invoking Gawk (gawk) Invoking Gawk (gawk) Other Arguments
automatically generated byinfo2html