nl(1) nl(1)
NAME
nl - number lines
SYNOPSIS
nl [option ...] [file]
DESCRIPTION
The nl command reads lines from a file or the standard input and
writes them on the standard output with line numbering.
nl views the text it reads in terms of logical pages. A logical page
consists of a header, a body, and a footer section. Empty sections are
valid.
The start of a header, body, and footer of a logical page is normally
signaled by an input line containing nothing but one of the following
strings:
____________________
| Line | Start of |
|_______|___________|
| \:\:\:| header |
|_______|___________|
| \:\: | body |
|_______|___________|
| \: | footer |
|_______|___________|
If the input text does not contain any delimiter characters, nl
assumes that the text being read is in a single logical page body.
Line numbering is reset at the start of a logical page (exception:
option -p). Different line numbering options are independently avail-
able for header, body, and footer (e.g. no numbering of header and
footer lines, while numbering blank lines only in the body).
OPTIONS
No option specified:
nl numbers all logical page body lines that contain printable
text, but not header and footer lines.
Line numbering is reset to 1 at the start of each logical page.
Within a logical page, nl numbers lines in increments of 1.
Each line number may be up to 6 positions long and is output
right justified without leading zeros. A tab is used to separate
line numbers from text.
The options must be entered individually, i.e. separated from other
options by blanks. The name of the file may be specified before,
between, or after the options. The position of the file name in the
command line has no effect on the operation of the nl command.
Page 1 Reliant UNIX 5.44 Printed 11/98
nl(1) nl(1)
Selecting the lines to be numbered
-b type
Specifies which logical page body lines are to be numbered.
type can be any of: a, n, pregexpr, or t.
a All lines are numbered.
n No lines are numbered.
pregexpr
Numbers all lines containing strings that match the given
regexpr.
regexpr is a simple (non-internationalized) regular expres-
sion [see expressions(5)]. If the specified regular expres-
sion contains shell metacharacters, it must be enclosed in
single quotes: p'reg_expr'.
t All lines with printable text are numbered.
-b not specified:
Only the lines with printable text are numbered. Option -b with
the t argument is thus the default.
-f type
Specifies which logical page footer lines are to be numbered.
type may be: a, n, pregexpr, or t.
Option -f not specified:
Logical page footer lines are not numbered. Option -f with the n
argument is thus the default.
-h type
Specifies which logical page header lines are to be numbered.
type may be: a, n, pregexpr, or t.
-h not specified:
Logical page header lines are not numbered. Option -h with the n
argument is thus the default.
Restarting line numbering
-p Line numbering is not restarted at logical page delimiters.
Page 2 Reliant UNIX 5.44 Printed 11/98
nl(1) nl(1)
-v startnum
Line numbering is restarted at startnum at the start of each log-
ical page.
startnum may be any number greater than or equal to 0.
-v not specified:
The line counter is reset to 1 at the start of each logical page.
Defining the increment
-i incr
incr is the increment value used to number logical page lines.
-i not specified:
The default increment is 1.
Defining the output format
-n format
format is the line numbering format.
The recognized values are: ln, rn, or rz.
ln Prints line numbers left justified, suppressing leading
zeros.
rn Prints line numbers right justified, suppressing leading
zeros.
rz Prints line numbers right justified, but with leading zeros.
-n not specified:
Line numbers are printed right justified, without leading zeros.
In other words, the -n option with argument rn is the default.
-s sep
Defines sep as the separator between line numbers and the corre-
sponding text lines. sep may be one or more characters.
-s not specified:
By default, line numbers and text lines are separated by a tab
character.
-w n Defines n as the number of positions for line numbers.
The maximum value for n is 100. If you specify a higher value, a
value of 100 is assumed.
Page 3 Reliant UNIX 5.44 Printed 11/98
nl(1) nl(1)
-w not specified:
Individual line numbers may be up to 6 positions long.
Numbering blank lines
-l n nl treats n consecutive blank lines as a single blank line.
Example:
$ nl -b a -l 2
results in only every second blank line being numbered when there
are several consecutive blank lines (none of the header and
footer lines are numbered).
-l not specified:
Each blank line is interpreted as one full line (n = 1).
Defining delimiters for header, body and footer
-d x[y]
Changes the delimiter characters that specify the start of a
header, body or footer section from \: to the string xy.
If a backslash (\) is to be specified for x or y, it must be
escaped by single quotes or a second backslash, e.g. -d'\*' or
-d\\*.
y not specified:
The start of a header, body or footer section is identified by
the string x: instead of \:, i.e. the second character retains
its default value.
-- If file begins with a dash (-), the end of the command-line
options must be marked with --.
file Name of the input file.
file not specified:
nl reads from standard input.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. If LCMESSAGES is undefined or is defined
as the null string, it defaults to the value of LANG. If LANG is like-
wise undefined or null, the system acts as if it were not internation-
alized.
Page 4 Reliant UNIX 5.44 Printed 11/98
nl(1) nl(1)
LCCOLLATE and LCCTYPE determine the behavior of ranges, equivalence
classes and character sets or character classes within regular expres-
sions.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
EXAMPLES
The file poems has the following contents:
\:\:\:
Taken from: Do you love me?
\:\:
The trouble with you
's you've lost a screw
I'm sorry it's you
but there's nothing to do
There'll be no abatements
there are no replacements
don't make a to-do
just say toodle-oo
I'm sorry I can't help you
you'd cost too much to redo
you'll have to be abolished
report to be demolished
\:
Ronald Laing
\:\:\:
Limerick
\:\:
A limerick packs laughs anatomical
into space that is short and economical;
But the good ones I've seen
so seldom are clean,
And the clean ones so seldom are comical.
\:
Author unknown
Page 5 Reliant UNIX 5.44 Printed 11/98
nl(1) nl(1)
Call nl without options
Example 1
$ nl poems
Taken from: Do you love me?
1 The trouble with you
2 's you've lost a screw
3 I'm sorry it's you
4 but there's nothing to do
5 There'll be no abatements
6 there are no replacements
7 don't make a to-do
8 just say toodle-oo
9 I'm sorry I can't help you
10 you'd cost too much to redo
11 you'll have to be abolished
12 report to be demolished
Ronald Laing
Limerick
1 A limerick packs laughs anatomical
2 into space that is short and economical;
3 But the good ones I've seen
4 so seldom are clean,
5 And the clean ones so seldom are comical.
Author unknown
Page 6 Reliant UNIX 5.44 Printed 11/98
nl(1) nl(1)
Number lines in increments of 10
Example 2
$ nl -v 10 -i 10 poems
Taken from: Do you love me?
10 The trouble with you
20 's you've lost a screw
30 I'm sorry it's you
40 but there's nothing to do
50 There'll be no abatements
60 there are no replacements
70 don't make a to-do
80 just say toodle-oo
90 I'm sorry I can't help you
100 you'd cost too much to redo
110 you'll have to be abolished
120 report to be demolished
Ronald Laing
Limerick
10 A limerick packs laughs anatomical
20 into space that is short and economical;
30 But the good ones I've seen
40 so seldom are clean,
50 And the clean ones so seldom are comical.
Author unknown
SEE ALSO
ed(1), pr(1), expressions(5).
Page 7 Reliant UNIX 5.44 Printed 11/98