#! /bin/csh -f # Last edited on 2001-01-02 02:55:53 by stolfi # Reads a file of word counts, as produced by "uniq -c" # Outputs a similar file, where the counts are followed by # the corresponding fractions relative to the total count and the cumulative fractions # up to and including the current line. # # Preserves blank lines and comments. set temp = "/tmp/$$" set addpgm = '/^#/{next} /^ *$/{next} /./{S+=$1;if(NF\!=2){print ("bad line «" $0 "»")>>"/dev/stderr";exit 1}} END{print S}' cat > ${temp} set total = "`cat ${temp} | /usr/bin/gawk '${addpgm}'`" if ("/${total}" == "/") set total = "1" cat ${temp} \ | /usr/bin/gawk \ ' BEGIN{S=0;} \ /^#/ {print;next} \ /^ *$/ {print;next} \ /./ { \ V=$1; S+=V; $1=""; \ printf "%7d %6.4f %7d %6.4f%s\n", \ V, (V/'"${total}"'), S, (S/'"${total}"'), $0; \ } \ ' /bin/rm -f ${temp}