diff options
Diffstat (limited to 'ipl/progs/filesect.icn')
-rw-r--r-- | ipl/progs/filesect.icn | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/ipl/progs/filesect.icn b/ipl/progs/filesect.icn new file mode 100644 index 0000000..fd01f54 --- /dev/null +++ b/ipl/progs/filesect.icn @@ -0,0 +1,51 @@ +############################################################################ +# +# File: filesect.icn +# +# Subject: Program to produce section of a file +# +# Author: Ralph E. Griswold +# +# Date: March 26, 2002 +# +############################################################################ +# +# This file is in the public domain. +# +############################################################################ +# +# This program writes the section of the input file starting at a +# specified line number and extending a specified number of lines. +# +# The specifications are given as integer command-line arguments; the +# first is the starting line, the second is the number of lines. For +# example, +# +# filesect 20 100 <input >output +# +# copies 100 lines from input to output, starting at line 20 of input. +# +# If the specifications are out of range, the file written is truncated +# without comment. +# +# +############################################################################ + +procedure main(argl) + local start, count + + start := argl[1] | stop("*** starting value missing") + count := argl[2] | stop("*** count missing") + + if not (start := integer(start) & start > 0) then + stop("starting value not positive integer") + if not (count := integer(count) & count >= 0) then + stop("starting value not non-negative integer") + + every 1 to start - 1 do + read() | exit() + + every 1 to count do + write(read()) | exit() + +end |