home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / awk / awk320.zip / WALK.AWK < prev    next >
Text File  |  1990-02-08  |  1KB  |  51 lines

  1. # from the article:
  2. # "A Walk Through AWK" by Leon S. Levy
  3. # SIGPLAN Notices, V18, #12, December 1983
  4.  
  5.                                 # Prepare a formatted listing of
  6.                                 # all occurances of a given keyword
  7.                                 # in a file
  8.  
  9. BEGIN {
  10.         pagesize = 16
  11.         outlines = 0
  12.         NR = -1;
  13. }
  14.  
  15. outlines % pagesize == 0 && length(lines) != 0 {
  16.                                 # new page initialization
  17.                                 # print the page header
  18.  
  19.         printf "\n Pages and lines where AWK occurs\n"
  20.         printf " Page        Lines\n"
  21.         printf " ____        _____\n\n"
  22.  
  23.         outlines = 6
  24.         newoutpage = 1
  25. }
  26.  
  27. /AWK/ {                         # if the string "AWK"
  28.                                 # occurs in the current record
  29.         occurances++
  30.         pageno = int(NR / 33) + 1
  31.         lineno = (NR % 66) + 1
  32.         if (lines == "") {
  33.                 pages = pageno
  34.                 lines = lineno
  35.         }
  36.         else if (pages == pageno && length(lines) < 40)
  37.                 lines = lines ", " lineno
  38.         else {
  39.                 printf "%5d        %s\n",pages, lines
  40.                 outlines++
  41.                 pages = pageno
  42.                 lines = lineno
  43.         }
  44. }
  45. END {
  46.         if (lines != "")
  47.                 printf "%5d        %s\n", pages, lines
  48.         printf "\n%d occurances of AWK\n", occurances
  49. }
  50.  
  51.