DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

nl(C)


nl -- add line numbers to a file

Syntax

nl [ -p ] [ -b type] [ -d delim] [ -f type ] [ -h type ] [ -i incr ] [ -l num ]
[ -n format ] [ -s sep ] [ -v start# ] [ -w width ] [ file ]

Description

nl reads lines from the named file, or the standard input if no file is named, and reproduces the lines on the standard output. Lines are numbered on the left in accordance with the command options in effect.

nl views the text it reads in terms of logical pages. Line numbering is reset at the start of each logical page. A logical page consists of a header, a body, and a footer section. Empty sections are valid. Different line numbering options are independently available for header, body, and footer (for example, no numbering of header and footer lines while numbering blank lines only in the body).

The start of logical page sections is signaled by input lines containing nothing but one or more pairs of backslash-followed-by-colon:

Page section Line contents
Header \:\:\:
Body \:\:
Footer \:

 +-------------+----------------------------------+
 |Page section | Line contents                    |
 +-------------+----------------------------------+
 |Header       | \:\:\:                           |
 +-------------+----------------------------------+
 |Body         | \:\:                             |
 +-------------+----------------------------------+
 |Footer       | \:                               |
 +-------------+----------------------------------+
Unless signaled otherwise, nl assumes the text being read is in a single logical page body.

Command options may appear in any order and may be intermingled with an optional filename. Only one file may be named. The options are:


-b type
Specifies which logical page body lines are to be numbered. Recognized types and their meaning are: a, number all lines; t, number only lines consisting entirely of printable characters; n, no line numbering; pstring, number only lines that contain the regular expression specified in string. Default type for logical page body is t.

-d delim
Specifies the two characters that show the start of a logical page section. The default characters are \:; if only one character is given for delim, nl assumes that the second should be ``:''.

-f type
Same as -b type except for footer. Default for logical page footer is n (no lines numbered).

-h type
Same as -b type except for header. Default type for logical page header is n (no lines numbered).

-i incr
incr is the increment value used to number logical page lines. The default is 1.

-l num
num is the number of blank lines to be considered as one. For example, -l2 results in only the second adjacent blank being numbered (if the appropriate -ha, -ba, and/or -fa option is set). The default is 1.

-n format
format is the line numbering format. Recognized formats are:

ln
left justified, leading zeroes suppressed

rn
right justified, leading zeroes suppressed

rz
right justified, leading zeroes kept

Default format is rn (right justified).


-p
Does not restart numbering at logical page delimiters.

-s sep
sep is the character(s) used in separating the line number and the corresponding text line. Default sep is a tab.

-v start#
start# is the initial value used to number logical page lines. The default is 1.

-w width
width is the number of characters to be used for the line number. The default width is 6.

Examples

Number the lines of the C program source file foo.c and print it:

nl foo.c | lp

See also

pr(C)

Standards conformance

nl is conformant with:

ISO/IEC DIS 9945-2:1992, Information technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities (IEEE Std 1003.2-1992);
AT&T SVID Issue 2;
X/Open CAE Specification, Commands and Utilities, Issue 4, 1992.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 03 June 2005