NL(1) User Commands NL(1)

nl - line numbering filter

nl [-htype] [-btype] [-ftype] [-vstart#] [-iincr] [-p] [-lnum] [-wwidth] [-nformat] [-ddelim] [file]

The nl command prints a file, or, when no file argument is given, standard input, preceding lines with line numbers on the left.

Lines with special content are taken as page delimiters. Three parts of pages are distinguished: header, body and footer. Each part is started when a line consisting only of the following characters appears in input:

Line contents Start of
\:\:\: header
\:\: body
\: footer

Line numbers are reset each time a header begins. The start of the file is considered a body part until a line marking another part appears.

The following options alter the behavior of nl:

Specifies which lines in a body part are numbered, where type is one of the following:
Number all lines, unless otherwise specified by the -l option.
Number all non-empty lines.
Number no lines.
Number all lines that match the regular expression string. Regular expressions are as in ed(1); /usr/5bin/nl uses simple regular expressions, /usr/5bin/posix/nl, /usr/5bin/posix2001/nl, and /usr/5bin/s42/nl use basic regular expressions.
The default is t.
Change the special characters that delimit parts of a page to the two characters in delim. If delim consists of only one character, the second character remains the default, `:'.
Specifies which lines in a footer part are numbered, where type has the format described for -b. The default is n.
Specifies which lines in a header part are numbered, where type has the format described for -b. The default is n.
Line numbers are increased by incr, which defaults to 1.
For the -ba, -fa, and -ha options, specifies which line of adjacent blank lines is printed. The default is 1 (print all blank lines).
Sets the format of line numbers, where format is one of:
left-justified, preceded by blanks
right-justified, preceded by blanks
right-justified, preceded by zeros
The default is rn.
Line numbers are not reset at the start of each header when this option is present.
Sets the string that separates line number and line content in output, default is a tabulator.
Each page is numbered starting at start#, which defaults to 1.
Sets the width of line numbers. If a number has fewer digits than width, it is padded as described for the -n option; if it has more digits, only the last width digits are printed. The default width is 6.

The file argument can appear between options. For /usr/5bin/nl and /usr/5bin/s42/nl, option and option argument must not be separated; if an option is not immediately followed by its argument, the default value is used. /usr/5bin/posix/nl and /usr/5bin/posix2001/nl require an option argument and accept it regardless of space between option and argument.

See locale(7).
Affects the collation order for range expressions, equivalence classes, and collation symbols in basic regular expressions.
Determines the mapping of bytes to characters.

To number all lines in a file, effectively disabling header and footer recognition since no line can contain a second newline character and thus the condition is never met:

nl -ba -d´
´ file

Note that there is no white space other than the newline character between ´ ´.

To number all lines that are not empty and contain at least one non-blank character:

nl -bp´[^      ]´ file

The characters between [ ] are: a circumflex, a space, and a tabulator.

ed(1), pr(1), locale(7)

Since the default width causes line numbers to be truncated if they consist of more than six digits, the -w option should be used to increase this value if higher numbers are to be expected.

8/14/05 Heirloom Toolchest