Unique Word Counter Needed

carl carl at bdaemon.UUCP
Sat Dec 14 02:21:36 AEST 1985


> 
> I need a way to count unique words in a document.
> Does any one have suggestions on a simple way to do this?

The following is a fancy version of what you want.  NOTE:  The precise
syntax of 'tr' varies among versions, so some diddling may be needed.
Good Luck!

------------------------------------------------------------
cat $* |			# tr reads the standard input
tr "[A-Z]" "[a-z]" |		# Convert all upper case to lower case
tr -cs "[a-z]\'" "\012" |		# Replace all characters not a-z to
				# a new line. i.e. one word per line

sort |				# uniq expects sorted input
uniq -c |			# Count the number of times each word appears
sort +0nr +1d |			# Sort first from most to least frequent,
				# then alphabetically.

pr -w80 -4 -h "Concordance for $*" 	# Print in four columns
------------------------------------------------------------

Carl Brandauer
daemon associates, Inc.
1760 Sunset Boulevard
Boulder, CO 80302
303-442-1731
{allegra|amd|attunix|cbosgd|ucbvax|ut-sally}!nbires!bdaemon!carl



More information about the Comp.unix mailing list