#! /usr/bin/gawk -f # Last edited on 2024-03-29 23:05:33 by stolfi # Prints sum and average of numbers in column 0 of a file. # Considers only noon-blank lines whose first field looks vaguely like a number, # namely stars with one digit preceded by optional sign and optional period. BEGIN {sum=0; n=0} /^ *[-+]?[.]?[0-9]/ { sum += $1; n++ } END { printf "sum = %d n = %d avg = %d", sum, n, (sum + (n/2))/n }