Awk

awk(1) is a scripting language designed for text processing.

There are several implementation of awk(1):

See the GNU awk User Manual for further documentation.


Example

awk 'BEGIN { print "hello world" }'

A better example is extracting the hostnames from the hosts file.

awk '/^[^#]/ { print $2 }' /etc/hosts

The awk syntax can be written to a script file and executed like:

awk -f my-hosts-parser.awk /etc/hosts

Shebang

To make an awk script executable, use #! /bin/awk -f as the shebang line.


Syntax


CategoryRicottone