AWK is a pattern scanning and processing language. There are several implementations of AWK (mostly in the form of interpreters). AWK has been codified in POSIX. The main implementations in use today are:
  • nawk (“new awk”, an evolution of oawk, the original UNIX implementation), used on *BSD and widely available on Linux;
  • mawk, a fast implementation that mostly sticks to standard features;
  • gawk, the GNU implementation, with many extensions;
  • the Busybox (small, intended for embedded systems, not many features).

If you only care about standard features, call awk, which may be Gawk or nawk or mawk or some other implementation. If you want the features in GNU awk, use gawk or Perl or Python.

Examples:
gawk ‘{ sum += $1 }; END { print sum }’ file
gawk -F: ‘{ print $1 }’ /etc/passwd

Usage: awk [POSIX or GNU style options] -f progfile [–] file …
Usage: awk [POSIX or GNU style options] [–] ‘program’ file …
POSIX options: GNU long options: (standard)

-f progfile –file=progfile
-F fs –field-separator=fs
-v var=val –assign=var=val
Short options: GNU long options: (extensions)
-b –characters-as-bytes
-c –traditional
-C –copyright
-d[file] –dump-variables[=file]
-D[file] –debug[=file]
-e ‘program-text’ –source=’program-text’
-E file –exec=file
-g –gen-pot
-h –help
-i includefile –include=includefile
-l library –load=library
-L[fatal|invalid] –lint[=fatal|invalid]
-M –bignum
-N –use-lc-numeric
-n –non-decimal-data
-o[file] –pretty-print[=file]
-O –optimize
-p[file] –profile[=file]
-P –posix
-r –re-interval
-S –sandbox
-t –lint-old
-V –version

Categories: Reference