: ########################################################################## # Shellscript: freq - word frequencies # Version : 0.1 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Written : 05.08.94 # Category : Text Utilities # SCCS-Id : $Id: freq,v 1.1.1.1 1999/06/15 19:29:05 heiner Exp $ ########################################################################## # Description # ########################################################################## PN=`basename $0` # program name VER='0.1 (beta)' Usage () { echo "$PN - count word frequencies, version $VER (stv '94) usage: $PN [file ...] The input is separated in words, and the frequency of every word is written to the standard output. The words are sorted by decreasing frequency. If no file name is given, $PN reads from standard input." >&2 exit 1 } Fatal () { for i do echo "$PN: $i" >&2 done exit 1 } [ $# -gt 0 -a "$1" = "-h" ] && Usage cat "$@" | awk ' {for (i=1;i<=NF;i++) Freq [$i]++} END { for ( i in Freq ) print i " " Freq [i] }' | sort -n +1 -r