home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum16.lzh / SOFTWARE / AWK / EXAMPLES / p119 < prev    next >
Text File  |  1991-05-06  |  498b  |  14 lines

  1. #   wordfreq - print number of occurrences of each word
  2. #   input : text
  3. #   output: number-word pairs sorted by numbers
  4.  
  5.     { gsub(/[.,:;!?(){}]/,"") 
  6.         for (i = 1; i <= NF; i++) count[$i]++ }
  7. END { for (w in count) print count[w], w }
  8.   
  9. #   The book (p.118) proposes a pipe in the END bracket. 
  10. #   This will not work, a procedure file workaround (or
  11. #   a command line pipe command must be used.
  12. #   Note - use SED to do case conversion, 
  13. #   so Bug and bug are counted as the same word
  14.