-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 posix
modifies mawk’s behavior to be more POSIX‐compliant:
• forces mawk not to consider ’\n’ to be space.
The original “posix_space” is recognized, but deprecated.
-W random=num
calls srand with the given parameter (and overrides the auto‐seeding behavior).
-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 traditional
Omit features such as interval expressions which were not supported by traditional awk.
-W usage
prints a usage message to stderr and exits (same as “-W help”).
-W version
mawk writes its version and copyright to stdout and compiled limits to stderr and exits 0.
mawk accepts abbreviations for any of these options, e.g., “-W v” and “-Wv” both tell mawk to show its version.
mawk allows multiple -W options to be combined by separating the options with commas, e.g., -Wsprint=2000,posix. This is useful for executable #! “magic number” invocations in which only one argument is supported,
e.g., -Winteractive,exec.
THE AWK LANGUAGE
1. Program structure
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, \. 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 ( expr ) statement
if ( expr ) statement else statement
while ( expr ) statement
do statement while ( expr )
for ( opt_expr ; opt_expr ; opt_expr ) statement
for ( var in array ) statement
continue
break
2. Data types, conversion and comparison
There are two basic data types, numeric and string. Numeric constants can be integer like -2, decimal like 1.08, or in scientific notation like -1.1e4 or .28E-3. All numbers are represented internally and all compu‐
tations are done in floating point arithmetic. So for example, the expression 0.2e2 == 20 is true and true is represented as 1.0.
String constants are enclosed in double quotes.
"This is a string with a newline at the end.\n"
Strings can be continued across a line by escaping (\) the newline. The following escape sequences are recognized.
\\ \
\" "
\a alert, ascii 7
\b backspace, ascii 8
\t tab, ascii 9
\n newline, ascii 10
\v vertical tab, ascii 11
\f formfeed, ascii 12
\r carriage return, ascii 13
\ddd 1, 2 or 3 octal digits