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