Add line numbers to nonblank lines of text in a file and write to standard output.


nl [options] [file]


-ba numbers all lines.

-bt numbers text lines only (the default).

-sc separates text from line numbers with the character c (the default is tab).

-wn uses n columns to show the line numbers.


The nl command adds a line number to each nonblank line of text from a file and writes the lines to standard output. Suppose the file sample.txt has the following lines:

A line followed by a blank line and then another non-blank line.

The nl command applied to this file produces the following result:

nl sample.txt
      1  A line followed by a blank line and
      2  then another non-blank line.