Pegasus InfoCorp: Web site design and web software development company

MAWK (1)

pattern scanning and text processing language

SYNOPSIS

    mawk [-W option ] [-F value ] [-v var=value ] [-\|-] 'program text' [file ...] mawk [-W option ] [-F value ] [-v var=value ] [-f program-file ] [-\|-] [file ...]

DESCRIPTION

    mawk is an interpreter for the AWK Programming Language. The AWK language is useful for manipulation of data files, text retrieval and processing, and for prototyping and experimenting with algorithms. mawk is a new awk meaning it implements the AWK language as defined in Aho, Kernighan and Weinberger, The AWK Programming Language, Addison-Wesley Publishing, 1988. (Hereafter referred to as the AWK book.) mawk conforms to the Posix 1003.2 (draft 11.3) definition of the AWK language which contains a few features not described in the AWK book, and mawk provides a small number of extensions.

    An AWK program is a sequence of pattern {action} pairs and function definitions. Short programs are entered on the command line usually enclosed in ' ' to avoid shell interpretation. Longer programs can be read in from a file with the -f option. Data input is read from the list of files on the command line or from standard input when the list is empty. The input is broken into records as determined by the record separator variable, RS. Initially, RS = "\en" and records are synonymous with lines. Each record is compared against each pattern and if it matches, the program text for {action} is executed.

OPTIONS

    -F value

      sets the field separator, FS, to value .

    -f file

      Program text is read from file instead of from the command line. Multiple -f options are allowed.

    -v var=value

      assigns value to program variable var .

    -\|-

      indicates the unambiguous end of options.

    The above options will be available with any Posix compatible implementation of AWK, and implementation specific options are prefaced with -W . mawk provides six:

    -W version

      mawk writes its version and copyright to stdout and compiled limits to stderr and exits 0.

    -W dump

      writes an assembler like listing of the internal representation of the program to stdout and exits 0 (on successful compilation).

    -W interactive

      sets unbuffered writes to stdout and line buffered reads from stdin. Records from stdin are lines regardless of the value of RS .

    -W exec file

      Program text is read from file and this is the last option. Useful on systems that support the #! "magic number" convention for executable scripts.

    -W sprintf=num

      adjusts the size of mawk's internal sprintf buffer to num bytes. More than rare use of this option indicates mawk should be recompiled.

    -W posix_space

      forces mawk not to consider '\en' to be space.

    The short forms -W [vdiesp] are recognized and on some systems -We is mandatory to avoid command line length limitations.

THE AWK LANGUAGE

    An AWK program is a sequence of pattern {action} pairs and user function definitions.

    A pattern can be:

      BEGIN END expression expression , expression

    One, but not both, of pattern {action} can be omitted. If {action} is omitted it is implicitly { print }. If pattern is omitted, then it is implicitly matched. BEGIN and END patterns require an action.

    Statements are terminated by newlines, semi-colons or both. Groups of statements such as actions or loop bodies are blocked via { ... } as in C. The last statement in a block doesn't need a terminator. Blank lines have no meaning; an empty statement is terminated with a semi-colon. Long statements can be continued with a backslash, \e\|. A statement can be broken without a backslash after a comma, left brace, &&, ||, do , else , the right parenthesis of an if , while or for statement, and the right parenthesis of a function definition. A comment starts with # and extends to, but does not include the end of line.

    The following statements control program flow inside blocks.

      if ( \*(ex ) statement

      if ( \*(ex ) statement else statement

      while ( \*(ex ) statement

      do statement while ( \*(ex )

      for ( opt_expr ; opt_expr ; opt_expr ) statement

      for ( var in array ) statement

      continue

      break