nl

number lines 

Command


SYNOPSIS

nl [-btype] [-dxy] [-ftype] [-htype] [-in] [-ln] [-nfmt] [-p] [-ssep] [-v[n]] [-w[n]] [file]


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:

-btype 

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.

-dxy 

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.

-ftype 

specifies the page footer numbering type (see the -b option). The default type is n.

-htype 

specifies the page header numbering type (see the -b option). The default type is n (no lines numbered).

-in 

sets the line increment to n rather than the default value of 1.

-ln 

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.

-nfmt 

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.

-ssep 

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:

0 

Successful completion.

1 

Failure due to any of the following:

— invalid command line argument
— more than one file name specified
— inability to open the file,
— invalid regular expression in -b, -f or -h
— invalid numbering type
— badly formed number in a command line option


PORTABILITY

x/OPEN Portability Guide 4.0. UNIX System V. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022.


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

Commands:
awk, pr

Miscellaneous:
regexp


PTC MKS Toolkit 10.4 Documentation Build 39.