#! /bin/csh -f 

# 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.

set temp = "/tmp/$$"

cat > ${temp}

set tots = ( `cat ${temp} | totalize-counts` )

cat ${temp} \
  | gawk \
      -v N=${tots[1]} -v S=${tots[2]} \
      ' BEGIN {printf "N=%d S=%d\n", N, S > "/dev/stderr"; } \
        /^#/ { print; } \
        /./ { V=$1; $1=""; printf "%7d %7.5f%s\n", V, ((V+1)/(S+N)), $0; } \
      '
      
/bin/rm -f ${temp}