[prev] [index] [next]

awk: a programmable filter (cont)

Awk automatically partitions each line into fields
(default field separator is any sequence of white-space chars)

Fields can be referenced as $1, $2, ... $NF.

NF counts number of fields on current line.

Variables:

  • have same syntax as C variables e.g. n, myVar
  • do not need to be declared   (be careful with naming)
  • are initialised to zero or ""   (not strongly typed)
String concatenation via adjacency e.g. "$1 ="$1", n="n