Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site jplgodo.UUCP Path: utzoo!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!oberon!smeagol!jplgodo!steve From: steve@jplgodo.UUCP (Steve Schlaifer x3171 156/224) Newsgroups: net.unix Subject: Re: Unique Word Counter Needed Message-ID: <529@jplgodo.UUCP> Date: Fri, 13-Dec-85 15:15:08 EST Article-I.D.: jplgodo.529 Posted: Fri Dec 13 15:15:08 1985 Date-Received: Sat, 14-Dec-85 13:28:22 EST References: <232@ihlpf.UUCP> Distribution: na Organization: Jet Propulsion Labs, Pasadena, CA Lines: 22 > > I need a way to count unique words in a document. > Does any one have suggestions on a simple way to do this? > gpw > > -- a simple (Bourne) shell script on system V is: awk '{ for(i=1; i<=NF; ++i) print $i }' file | sort | uniq -c prints a sorted list of the words in *file* preceded by a count of the number of times each word appeared in the file. I expect this will work on other systems but don't have enough experience to really know. To just count the number of distinct words in file change uniq -c to uniq | wc -l To list words that only occur once, add | awk '$1==1 { print $2 }' to the end of the pipe. There are many other variations on this that will occur to you as you play with it. Enjoy, Steve Schlaifer ( {group3 | smeagol}!jplgodot!steve )