home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / dellines.icn < prev    next >
Text File  |  2000-07-29  |  2KB  |  57 lines

  1. ############################################################################
  2. #
  3. #    File:     dellines.icn
  4. #
  5. #    Subject:  Program to delete lines from a file
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 28, 1996
  10. #
  11. ############################################################################
  12. #
  13. #  This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program is designed to delete a few specified lines from a file.
  18. #  The line numbers are given on the command line, the file is read from
  19. #  standard input and the lines that are not deleted are written to standard
  20. #  output as in
  21. #
  22. #    dellines 46 23 119 <infile >outfile
  23. #
  24. #  which writes all lines but 23, 46, and 119 of infile (if it contains that
  25. #  many lines) to outfile.
  26. #
  27. #  Line numbers do not have to be given in order.  Numbers less than 1 are
  28. #  ignored, but a nonnumerical argument is treated as an error.
  29. #
  30. ############################################################################
  31.  
  32. procedure main(lines)
  33.    local i, line
  34.  
  35.    if *lines = 0 then stop("*** no lines specified")
  36.  
  37.    every i := 1 to *lines do
  38.       lines[i] := integer(lines[i]) |
  39.          stop("*** nonnumeric argument: ", image(lines[i]))
  40.  
  41.    lines := set(lines)            # inefficient method but easy
  42.  
  43.    i := 0
  44.  
  45.    while line := read() do {
  46.       i +:= 1
  47.       if not member(lines, i) then {
  48.          write(line)
  49.          delete(lines, i)        # so trailing lines aren't tested
  50.          if *lines = 0 then break
  51.          }
  52.       }
  53.  
  54.    while write(read())
  55.  
  56. end
  57.