Number lines in a file
The nl command numbers, by default, all non-blank lines in a file.
Used without any options, nl numbers each non-blank line and display the result to standard output:
To number all lines, including empty ones, use the -b a option:
To increment line numbers with some other value (instead of the default 1,2,3,4…), use the -i option:
To add some custom string after line numbers, use the -s option:
To number only lines that match the specified regular expression, use the -b pREGEXP option. For example, to number only lines that begin with T, use the following command:
You can specify the numbering format with the -n format option. Available formats are ln (left justified, no leading zeros), rn (right justified, no leading zeros), and rz (right justified with leading zeros):