#!/usr/bin/awk -f #Averages a column from a given file. The filename # must be the first arg, and the column the second one # hence it can only be used in a pipeline by using - # to indicate stdin as the input 'file'. # #Note the use of 'delete ARGV[2]' to stop awk thinking #that we are passing in a list of files to process. # #Any empty lines at the start or end of the file will be counted #as 'zero' and will affect the average. BEGIN { i=ARGV[2] ; delete ARGV[2] ; count=0 } { sum += $i ; count ++ } END { printf "%5.2f\n", (sum/count) }