line extracts selected lines, specified by line number, from standard input or named files. Line numbers are 1-based.
The line numbers to be extracted may be specified in several ways. The most basic is to indicate individual line numbers individually, or line number ranges using the notation m-n. Multiple line numbers or ranges may be separated by commas, or entered as separate arguments. For example, the invocation
line 1,5,10-20 inputfilewould print lines 1, 5, and 10 through 20 of the file named inputfile. An equivalent invocation would be
line 1 5 10-20 inputfile
In the m-n notation, either m or n (but not both) may be omitted. The notation -n means from the beginning of the file up to line n. The notation m- means from line m to the end of the file.
Because multiple line numbers may be entered as separate arguments, there is an ambiguity if an input filename has a name which looks like a number. To resolve the ambiguity, use an alternative pathname for the file which does not begin with a digit. The simplest way to do so is to precede the numeric filename with ``./''.
It is also possible to specify line numbers or ranges using explicit option flags:
-f m -p nis equivalent to
-f m -t m+n-1(or to -f m -e m+n ).
Any number of -f, -t, -e, and -p options may appear. When these options are used, lone numbers on the command line are not interpreted as line numbers or ranges, and are therefore unambiguously usable as filenames.
The -f, -t, -e, and -p options are intended for use in shell scripts, when a complicated set of line number ranges is being built up on-the-fly, and when constructing a single string containing many dashes and commas would be even more cumbersome.
When line is invoked with multiple input filenames, the specified lines are selected from all files. For example,
line 5,10 a b cwould print lines 5 and 10 of file a, followed by lines 5 and 10 of file b, followed by lines 5 and 10 of file c. To select lines from the concatenation of many input files, use cat(1) and a pipeline:
cat a b c | line 5,10
The m-n line-selection syntax also supports ``relative'' (counted) range increments, analogous to the -p option. The notation m:n is equivalent to m-m+n-1. For example, the invocation
line 5:10,20 inputfilewould print 10 lines beginning with line 5 (that is, lines 5 through 14), followed by line 20.
line was inspired by a program of the same name and basic functionality conceived by Philip Lantz at Tektronix MDP circa 1985.
This documentation corresponds to version 2.3 of the program.
See http://www.eskimo.com/~scs/src/#line for possible updates.
Steve Summit, firstname.lastname@example.org