2.4.1. awk#

awk selects, transforms, and calculates with fields in structured text.

2.4.1.1. Common awk usage#

Treating a text file, where each space separates a column, you can print a column with:

awk '{print $1}' file

Where $1 is the first column. Index starts at 1.

2.4.1.2. Separator#

You can chose the field separator with, -F. Here, the comma is a separator to print the 5th column:

awk -F ',' '{print $5} file'

2.4.1.3. awk can do math.#

Average a column:

awk '{ total += $2; count++ } END { print total/count }' file

Add to value in column

awk '{print $1 + 1}' file