I have this homework question:
create function agg, first argument is filename, second will be sum, avg or min. script will compute sum, average or minimum (dependig on 2. argument) from the numbers in the file (1. arg.). Consider only one column file, one number per line.
I came up with this function:
agg(){
cat $1 | awk '{sum+=$1} END{print "sum of first column = "sum}'
cat $1 | awk '{sum+=$1} END { print "Average = ",sum/NR}'
cat $1 | awk 'min=="" || $1 < min {min=$1} END{ print "min="min}'
}
agg y
my script works fine but without the arguments. How can I incorporate the arguments? thanks!!