4/12/2019

sumcol

#!/bin/csh -f
if ($#argv != 2) then
echo "you must give exactly two parameters, first for name of file and second for column number"
else
set file = $argv[1]
set column = $argv[2]

set sumcol = `awk -v col=$column '{ sum+=$col} END {print sum}' $file `
set max = `awk -v col=$column 'NR==1{max = $col + 0; next} {if ($col > max) max = $col;} END {print max}' $file `
set min = `awk -v col=$column 'NR==1{min = $col + 0; next} {if ($col < min) min = $col;} END {print min}' $file `
#awk '{ sum+=$("$column")} END {print sum}'


echo ""
/bin/echo -e "Sum of column $column of file '$file' is \033[0;31m "$sumcol" \033[0m "
echo ""
/bin/echo -e "Max of column $column of file '$file' is \033[0;34m "$max" \033[0m "
echo ""
/bin/echo -e "Min of column $column of file '$file' is \033[0;35m "$min" \033[0m "
echo ""

endif