nl
[options] [file]Number the lines of file in logical page segments. Numbering resets to 1 at the start of each logical page. Pages consist of a header, body, and footer; each section may be empty. It is the body that gets numbered. The sections are delimited by special standalone lines as indicated next; the delimiter lines are copied to the output as empty lines.
\:\:\: | Start of header |
\:\: | Start of body |
\: | Start of footer |
-b
typeNumber lines according to type. Values are:
a | All lines. |
n | No lines. |
t | Text lines only (the default). |
p" exp" | Lines matching the regular expression exp only. |
-d
xyUse characters xy to delimit logical pages (default is \:
).
-f
typeLike -b
, but number footer (default type is n
).
-h
typeLike -b
, but number header (default type is n
).
-i
nIncrement each line number by n (default is 1).
-l
nCount n consecutive blank lines as one line.
-n
formatSet line number format. Values are:
ln | Left-justify, omit leading zeros. |
rn | Right-justify, omit leading zeros (default). |
rz | Right-justify. |
-p
Do not reset numbering at start of pages.
-s
cSeparate text from line number with character(s) c (default is a tab).
-v
nNumber each page starting at n (default is 1).
-w
nUse n columns to show line number (default is 6).
List the current directory, numbering files as 1), 2), etc.:
ls | nl -w3 -s') '
Number C source code and save it:
nl prog.c > print_prog
Number only lines that begin with #include
:
nl -bp"^#include" prog.c