NL(1) | General Commands Manual | NL(1) |
nl
— line
numbering filter
nl |
[-p ]
[-b type]
[-d delim]
[-f type]
[-h type]
[-i incr]
[-l num]
[-n format]
[-s sep]
[-v startnum]
[-w width]
[file] |
The nl
utility reads lines from the named
file, applies a configurable line numbering filter
operation, and writes the result to the standard output. If
file is a single dash
(‘-
’) or absent,
nl
reads from the standard input.
The nl
utility treats the text it reads in
terms of logical pages. Unless specified otherwise, 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
sections.
The starts of logical page sections are signalled by input lines containing nothing but one of the following sequences of delimiter characters:
Line | Start of |
\:\:\: | header |
\:\: | body |
\: | footer |
If the input does not contain any logical page section signalling directives, the text being read is assumed to consist of a single logical page body.
The following options are available:
-b
typea
t
n
p
exprThe default type for logical page body
lines is t
.
-d
delim\:
”.-f
type-b
type
except for logical page footer lines. The default
type for logical page footer lines is
n
.-h
type-b
type
except for logical page header lines. The default
type for logical page header lines is
n
.-i
incr-l
num-b
a
, -f
a
or -h
a
option, specify the number of adjacent blank
lines to be considered as one. For example, -l
2
results in only the second adjacent blank line being numbered. The default
num value is 1.-n
formatln
rn
rz
The default format is
rn
.
-p
-s
sep-v
startnum-p
option. The default
startnum value is 1.-w
widthThe LANG
, LC_ALL
,
LC_CTYPE
and LC_COLLATE
environment variables affect the execution of nl
as
described in environ(7).
The nl
utility exits 0 on success,
and >0 if an error occurs.
Number all non-blank lines:
$ echo -e "This is\n\n\na simple text" | nl 1 This is 2 a simple text
Number all lines including blank ones, with right justified line numbers with leading zeroes, starting at 2, with increment of 2 and a custom multi-character separator:
$ echo -e "This\nis\nan\n\n\nexample" | nl -ba -n rz -i2 -s "->" -v2 000002->This 000004->is 000006->an 000008-> 000010-> 000012->example
Number lines matching regular expression for an i followed by either m or n
$ echo -e "This is\na simple text\nwith multiple\nlines" | nl -bp'i[mn]' This is 1 a simple text with multiple 2 lines
The nl
utility conforms to
IEEE Std 1003.1-2001 (“POSIX.1”).
The nl
utility first appeared in
AT&T System V Release 2 UNIX.
Input lines are limited to LINE_MAX
(2048)
bytes in length.
January 26, 2005 | Mac OS X 12 |