awk

Aho, Weinberger, and Kernighan’s C-like programming language

Standard Input: Used only if no list-of-files is given

Standard Output: Used to display results

Note

On some systems, use nawk (new awk) or gawk (GNU awk).

Using awk from the command line to display selected lines:

awk '$n == "string"' [list-of-files]
   (display line if field n equals string)
awk '$n > 3.5' [list-of-files]
   (display line if field n is greater than value.
    can also test ==, !=, >, <, >=, <=)
awk '$n ~ /R.E./' [list-of-files]

Using awk to display selected fields:

awk '{print $1, $5, $0}' [list-of-files]
awk '{if ($5 > 20000) $5=20000} {print "file: " $9         "       " $5}'
awk '{ printf("Name: %16s, Size: %5d, Blocks:                   %6.2f\n", $9, $5,
$5/512)}'

Using awk from the command line ...

Get Practical UNIX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.