Text Processing

nl

Number lines of files with configurable format and starting number.

Synopsis

syntax
nl [OPTION]... [FILE]...

Examples

Number non-empty lines
nl file.txt
Number all lines including blank
nl -ba file.txt
Number with dot separator and 3-digit width
nl -s'. ' -w 3 file.txt
Right-justified zero-padded line numbers
nl -nrz file.txt

Common options

FlagDescription
-bBody line numbering style (a=all, t=non-empty, n=none)
-nNumber format (ln, rn, rz)
-sSeparator between number and line
-wNumber width

About nl

The `nl` command number lines of files with configurable format and starting number. Text processing commands transform, format, and generate text output.

Linux's philosophy of small composable tools shines here — these commands are designed to be piped together to build complex text-processing workflows. They are indispensable for scripting, log analysis, and data transformation tasks.

The command accepts 4 commonly used flags shown above, though the full set of options is available in the man page (`man nl`). The 4 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More Text Processing Commands

Other commands in the Text Processing category

Related tools