gno/usr.bin/awk/tests/percent

11 lines
263 B
Plaintext
Raw Normal View History

# percent
# input: a column of nonnegative numbers
# output: each number and its percentage of the total
{ x[NR] = $1; sum += $1 }
END { if (sum != 0)
for (i = 1; i <= NR; i++)
printf("%10.2f %5.1f\n", x[i], 100*x[i]/sum)
}