Yeah, you're right and while we're addressing that we may as well fix the END
block to print numbers even if the file is empty:
END {
printf "sum = %d\n", sum
printf "ave = %d\n", (NR ? sum / NR : 0)
printf "min = %d\n", min
printf "max = %d\n", max
}
or if we want "NaN"s printed in that situation:
END {
print "sum =", (NR ? sum + 0 : "NaN")
print "ave =", (NR ? sum / NR : "NaN")
print "min =", (NR ? min + 0 : "NaN")
print "max =", (NR ? min + 0 : "NaN")
}
Note that to force printing a numeric value (0) from a variable that may not
have been populated, you can use either:
printf "%d\n", var
or
print var + 0
I showed both ways above, it's a style choice.
Regards,
Ed.