community man page

nl

Number lines from a file or from `stdin`.

16 examples·source: tldr · CC-BY·status: verified
Reading is open to everyone. Suggesting a flag, fixing an example or adding a recipe is opening to verified-email accounts soon — every change is moderated before it goes live.
curl https://curlhub.sh/man/nl
same page, in your terminal

Examples

Number non-blank lines in a file GNU

nl path/to/file

Read from `stdin` GNU

command | nl

Number all body lines including blank lines or do not number body lines GNU

nl [-b|--body-numbering] a|n path/to/file

Number only the body lines that match a basic `regex` (BRE) pattern GNU

nl [-b|--body-numbering] p'FooBar[0-9]' path/to/file

Use a specific increment for line numbering GNU

nl [-i|--line-increment] increment path/to/file

Specify the line numbering format to right or left justified, keeping leading zeros or not GNU

nl [-n|--number-format] rz|ln|rn

Specify the line numbering's width (6 by default) GNU

nl [-w|--number-width] col_width path/to/file

Use a specific string to separate the line numbers from the lines (`TAB` by default) GNU

nl [-s|--number-separator] separator path/to/file

Number non-blank lines in a file

nl path/to/file

Read from `stdin`

command | nl -

Number all body lines including blank lines or do not number body lines

nl -b a|n path/to/file

Number only the body lines that match a basic `regex` (BRE) pattern

nl -b p'FooBar[0-9]' path/to/file

Use a specific increment for line numbering

nl -i increment path/to/file

Specify the line numbering format to right or left justified, keeping leading zeros or not

nl -n rz|ln|rn

Specify the line numbering's width (6 by default)

nl -w col_width path/to/file

Use a specific string to separate the line numbers from the lines (`TAB` by default)

nl -s separator path/to/file