SYNOPSIS
nl
[
DESCRIPTION
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).
Input Line | Starts |
|
|
\:\:\: | page header |
\:\: | page body |
\: | page footer |
Table 1: nl Logical Page Delimiter Characters
There are numerous options to control the precise nature of the line numbering:
-b type-
specifies the numbering type for each page body. The numbering type is one of:
- a
-
numbers all lines.
- n
-
does not number any lines.
- pregexp
-
numbers only those lines which contain the basic regular expression regexp. See regexp for details.
- t
-
numbers only those lines that are not empty. An empty line consists of only a newline character.
The default body numbering type is t.
-d xy-
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.
-f type-
specifies the page footer numbering type (see the
-b option). The default type is n. -h type-
specifies the page header numbering type (see the
-b option). The default type is n (no lines numbered). -i n-
sets the line increment to n rather than the default value of 1.
-l n-
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.
-n fmt-
specifies the line numbering format, which must be one of the following:
- n
-
right justified line number, padded to width (see
-w ) on the left with spaces (the default format). - rz
-
right justified line number, padded on left with zeroes.
- ln
-
left justified line number, padded on right with spaces.
-p -
specifies continuous page numbering across page boundaries. By default, nl restarts numbering (as in the next option) at each new page.
-s sep-
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.
-v [n]-
starts numbering for each new page at n. If this option is not specified, page numbering starts at 1.
-w [n]-
sets the width of the line number in the output to n. If this is not specified, the default is 6.
EXAMPLE
The following command numbers every second consecutive blank line, using page delimiters of ~!:
nl -l2 -ha -ba -fa -nrz -v10 -i10 -d~! file
DIAGNOSTICS
Possible exit status values are:
PORTABILITY
x/OPEN Portability Guide 4.0. UNIX System V. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022. Windows Server 2025.
AVAILABILITY
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
SEE ALSO
- Miscellaneous:
- regexp
PTC MKS Toolkit 10.5 Documentation Build 40.