Pages

Sunday, July 27, 2014

Using AWK



awk is a script interpreter designed to process tuples (records) of data structured into columnar fields.
Probably the most common awk implementation today is GNU's gawk found in most linux distros.

Awk is block structured and an awk script takes the general form:

[BEGIN{<commands to execute before processing records>}]{<commands to execute for each record>}[END{<commands to execute after all records are processed>}]

Summing values...
Assuming <somefile> has a number as it's second awk parseable field the following should sum those values from each record in the file.
cat <somefile> | awk '{size=size+$2}END {print size}'