home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume1 / xref / mergelines.awk < prev    next >
Encoding:
AWK Script  |  1986-11-30  |  847 b   |  24 lines

  1. # Input: lines of the form "name \t file \t line number"
  2. # Output: merged lines of the form "name \t file \t n1 n2 n3 ..."
  3. #   Starts a new line for new names or files, and when line gets long.
  4. #   Suppresses name and previous file on continuation lines.
  5.  
  6. BEGIN { # Print header and compute usable width
  7.     fmt = "%-14s\t%-14s\t%s\n"
  8.     printf fmt, "NAME", "FILE", "LINE NUMBERS"
  9.     ###uwidth = '$width'-16-16-5;  # sizes of name, file, number
  10.     if (uwidth<3) uwidth=80-16-16-5;  }
  11.  
  12. $1 != name { printf fmt, pname, pfile, line;  
  13.     name = pname = $1;  file = pfile = $2;  line = "" }
  14.  
  15. $2 != file { printf fmt, pname, pfile, line;  
  16.     pname = "";  file = pfile = $2;  line = "" }
  17.  
  18. length(line) > uwidth { printf fmt, pname, pfile, line;  
  19.     pname = "";  pfile = "";  line = "" }
  20.  
  21. { line = line " " sprintf("%4s",$3) }
  22.  
  23. END { printf fmt, pname, pfile, line }
  24.