LINES v1.31 - print specifically numbered lines |
Documentation revised 21 Oct 00 - Copyright (c) 1996-2000 by Rune Berg. TextTools Freeware. |
Contents:
Usage | Top || Next |
lines [log logfile] [options] [infile] [to outfile] LN [...]
See Understanding The Usage Section for details.
Description | Top || Previous || Next |
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 | Top || Previous || Next |
The command:
lines myfile.txt 3 20-30 44
prints lines 3, 20 .. 30, and 44 of "myfile.txt" to the screen.
Options | Top || Previous || Next |
lines recognizes the following command line options:
Option | Function |
---|---|
-v | Print version banner and usage info to standard error (or logfile, if given), then exit. |
-c | When all LNs are processed, continue copying as
according to the "skip-copy commands" implied by the 2nd .. last LNs. This option requires at least 2 LNs. See discussion below for more details. |
Limitations | Top || Previous || Next |
The highest allowed LN is 2147483647 (over- and underflows are not detected).
lines accepts up to 100 LNs.
Discussion | Top || Previous || Next |
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
Return Codes | Top || Previous || Next |
lines returns with one of the following codes ("error levels"):
Code | Meaning |
---|---|
0 | Success |
101 | Out of memory |
102 | Incorrect/missing command line arguments |
104 | Error opening file |
106 | Capacity overrun |
105 | I/O Error |
107 | File name clash |
For more details, see TextTools General Features.
Version History | Top || Previous |
These are the released versions of lines:
Version | Date | Changes |
---|---|---|
1.00 | 25-Feb-96 | n/a |
1.10 | 26-Sep-96 |
|
1.20 | 13-Jul-97 |
|
1.30 | 2-Jan-99 |
|
1.31 | 21-Oct-00 |
|
End of document |