Unique Word Counter Needed

Heiby heiby at cuae2.UUCP
Thu Dec 12 06:30:34 AEST 1985


Here's something I threw together.  This sequence assumes that case
is not significant.  Also, its idea of what is a word may not match
yours.  For example This will cound troff controls as words.  The
first "tr" is from the SVR2 tr man page.  The text says, "The
following example creates a list of all the words in file1 one per
line in file2, where a word is taken to be a maximal string of
alphabetics."  (I am using pipes rather than files, though.)

cat FILE |			# FILE is the input file
tr -cs "[A-Z][a-z]" "[\012*]" |	# split the words
tr "[A-Z]" "[a-z]" |		# make all lower case
sort |				# sort them
uniq |				# remove duplicates
wc -l				# display final count
-- 
Ron Heiby {NAC|ihnp4}!cuae2!heiby   Moderator: mod.newprod & mod.unix
AT&T-IS, /app/eng, Lisle, IL	(312) 810-6109
"I am not a number!  I am a free man!" (#6)



More information about the Comp.unix mailing list