#! /usr/bin/gawk -f # Last edited on 2003-11-20 22:54:24 by stolfi function error(msg) { printf "line %d: %s\n", NR, msg > "/dev/stderr"; abort = 1; exit(1); } BEGIN { abort =0; uc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; lc = "abcdefghijklmnopqrstuvwxyz"; for (i=1;i<=26;i++) { c = substr(uc,i,1); val[c] = +i; c = substr(lc,i,1); val[c] = -i; } val["0"] = 0; split("", hist); nsamples = 0; } /^[a-zA-Z0] *$/ { if (abort) exit 1; i = val[$1]; if (i == -0) i = 0 if (! (i in hist)) hist[i] = 0; hist[i]++; nsamples++; next; } END { for (i=-26; i<=+26; i++) { if (! (i in hist)) hist[i] = 0; printf "%6.1f %6d %6.1f %8.3f\n", i-0.5, i, i+0.5, 100*(hist[i]/nsamples) } }