# LINES v1.10 - print specifically numbered lines

#### Revised 2-Apr-97. Copyright (c) 1996-97 by Rune Berg. TextTools Freeware.

Usage - Description - Example - Options - Limitations - Discussion

### USAGE

lines [log logfile] [options] [infile] [to outfile] LN [...]

### DESCRIPTION

lines copies the LN'th line(s) from infile to outfile.

Each LN must be of one of the forms:

            4        ; 4th line
            10-20    ; 10th to 20th line

Line numbering starts at 1.

LNs must be in ascending order.

If the input does not have enough lines to satisfy all LN arguments, lines copies what it can.

If you don't specify infile, lines reads from standard input.
If you don't specify outfile, lines writes to standard output.
If you don't specify logfile, lines writes error messages to standard error.

### EXAMPLE

The command:

            lines myfile.txt 3 20-30 44

prints lines 3, 20 .. 30, and 44 of "myfile.txt" to the screen.

### OPTIONS

-v : Print version banner and usage info to standard error (or logfile, if given), then exit.

-c : When all LN's are processed, continue copying as according to the "skip-copy commands" implied by the 2nd .. last LN's. This option requires at least 2 LN's. See discussion below for more details.

### LIMITATIONS

The highest allowed LN is 32767 on DOS, 2147483647 on Win32 (over- and underflows are not detected).

lines accepts up to 100 LNs.

### DISCUSSION

Here follows as more thorough description of lines's behaviour, especially with regard to the -c option.

From the LN's given on the command line, lines builds (internally) a list of "skip-and-copy" commands.
For example, for the LN's:

            2-4 7 14-20

lines build this list:

            skip 1 line
            copy 3 lines

            skip 2 lines
            copy 1 line

            skip 6 lines
            copy 7 lines

lines then processes the input file according to the list, and exits after the last copy command is done.

However, if you give the the -c option, lines does not exit after the last copy command, but loops back to the second skip command and continues processing:

            skip 1 line
            copy 3 lines

            skip 2 lines  <-+
            copy 1 line     |
                            |
            skip 6 lines    |
            copy 7 lines  --+

This continues until the entire input file has been processed.

Now, let's look at how to make lines deal with some typical inputs:

1. A report, stored in the file "report.txt", where each page consists of 3 header lines, 60 data lines, and 3 footer lines:

            header (line 1)
            header (line 2)
            header (line 3)
            data   (line 4)
            ...
            data   (line 63)
            footer (line 64)
            footer (line 65)
            footer (line 66)
            header (line 67)
            header (line 68)
            header (line 69)
            data   (line 70)
            ...
            data   (line 129)
            footer
            footer
            footer
            etc.

We want to extract only the data lines. Here's how:

            lines -c report.txt to data.txt 4-63 70-129

This command line makes lines work according to the following skip-and-copy commands:

            skip 3
            copy 60

            skip 6  <-+
            copy 60 --+

2. A file from which we want copy every second line, starting at line 1:

            lines -c myfile.txt to 135etc.txt 1 3

3. A file from which we want copy every second line, starting at line 2:

            lines -c myfile.txt to 246etc.txt 2 4

##### End of document