nl is a filter that numbers lines in a single file. If file is not specified on the command line, the standard input is used.
The input is viewed as a stream of text lines, possibly divided into logical pages by separators. In turn, each page may consist of a header, body and/or footer, in that order. Any missing part is assumed to be empty. Using the default page delimiter character of \ and :, lines consisting entirely of the combinations shown in Table 1 are logical page part delimiters (and are not numbered).
Table 1: nl Logical Page Delimiter Characters
There are numerous options to control the precise nature of the line numbering:
specifies the numbering type for each page body. The numbering type is one of:
numbers all lines.
does not number any lines.
numbers only those lines which contain the basic regular expression regexp. See regexp for details.
numbers only those lines that are not empty. An empty line consists of only a newline character.
The default body numbering type is t.
changes the default delimiter characters (\ and : mentioned earlier) to characters x and y. If only x is specified, only the first delimiter character is changed.
specifies the page footer numbering type (see the
-boption). The default type is n. -htype
specifies the page header numbering type (see the
-boption). The default type is n (no lines numbered). -in
sets the line increment to n rather than the default value of 1.
treats blank lines specially when the page numbering type is a (all). Every nth consecutive blank line is numbered. When this option is not specified, n defaults to 1 and every blank line is numbered.
specifies the line numbering format, which must be one of the following:
right justified line number, padded to width (see
-w) on the left with spaces (the default format).
right justified line number, padded on left with zeroes.
left justified line number, padded on right with spaces.
specifies continuous page numbering across page boundaries. By default, nl restarts numbering (as in the next option) at each new page.
prints the string sep to separate the line number from the text of the line being numbered. When this option is not specified, this separator is a single tab character.
starts numbering for each new page at n. If this option is not specified, page numbering starts at 1.
sets the width of the line number in the output to n. If this is not specified, the default is 6.
The following command numbers every second consecutive blank line, using page delimiters of ~!:
nl -l2 -ha -ba -fa -nrz -v10 -i10 -d~! file
Possible exit status values are:
Failure due to any of the following:
x/OPEN Portability Guide 4.0. UNIX System V. Windows 7. Windows Server 2008 R2. Windows 8. Windows Server 2012. Windows 10. Windows Server 2016.
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.1 Documentation Build 15.