home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / programm / 4356 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  1.0 KB

  1. Path: sparky!uunet!olivea!decwrl!sdd.hp.com!usc!rpi!fitzgb
  2. From: fitzgb@mml0.meche.rpi.edu (Brian Fitzgerald)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: text file word counter ?
  5. Message-ID: <!lfy8n#@rpi.edu>
  6. Date: 18 Aug 92 21:35:49 GMT
  7. References: <1992Aug18.102143.1@vax.sonoma.edu>
  8. Organization: Rensselaer Polytechnic Institute, Troy, NY
  9. Lines: 23
  10. Nntp-Posting-Host: mml0.meche.rpi.edu
  11.  
  12. mccalld@vax.sonoma.edu writes:
  13. >Greetings:
  14. >     Looking for a programming package which counts the number of unique
  15. >words in a file and displays the results, and also counts the number of
  16.  
  17. deroff -w [file] | sort | uniq -d | wc -w    (Yuck!)
  18.  
  19. or
  20.  
  21. deroff -w [file] | tr A-Z a-z | sort | uniq -d | wc -w
  22.  
  23. >times each unique word appears within the file.......
  24.  
  25. deroff -w [file] | awk '{w[$1]++};END{for (i in w){print i, w[i]}}' ...
  26.  
  27. (based on Aho, Kernighan, and Weinberger, "The AWK Programming 
  28. Language", Addison Wesley, 1988)
  29.  
  30. where ... can be "| sort", "| sort -n +1", "| sort -f", etc...
  31.  
  32. If [file] is omitted, the pipeline reads from the standard input.
  33.  
  34. Brian
  35.