Linux / Unix: Add Line Numbers To Files

Linux / Unix: Add Line Numbers To Files

To add line numbers to a file on Linux or Unix, you can use the nl command.

The nl command is a utility that adds line numbers to the input file and writes the output to the standard output. By default, nl adds line numbers to the left margin of the output, but you can specify a different numbering style using command line options.

Here is an example of how to use the nl command to add line numbers to a file called input.txt:

nl input.txt
So‮.www:ecru‬lautturi.com

This will add line numbers to the input.txt file and write the output to the standard output (usually the terminal).

To save the output to a new file called output.txt, you can use the > operator to redirect the output to the file:

nl input.txt > output.txt

This will create a new file called output.txt that contains the input file with line numbers added.

You can also use command line options to customize the line numbering style. For example, to add line numbers to the right margin of the output, you can use the -w option followed by the number of spaces to reserve for the line numbers:

nl -w 5 input.txt > output.txt

This will add line numbers to the right margin of the output, reserving 5 spaces for the line numbers.

Created Time:2017-10-29 22:08:58  Author:lautturi