
They were listed above in order of simplicity, but we’ll offer an ‘awk’ solution below too. Several readers chimed in the comments to provide easier solutions to numbering lines within a text file. That’s all there is to it! You can use either trick.

Nl -ba -s ': ' filename > filenamenumbered You can also use the ‘nl’ command as described next: Hard Core Line Numbers into a Texts File Using the nl CommandĪgain, replace “filename” and “filenamenumbered” with the appropriate name of the file you are adding line numbers to:

Simply replace “file” with the file name you want to add line numbers to, and change “file_name” to the exported name. To get started, get to the Terminal and you’ll want to do the following at the command line prompt: Using cat to Add Line Numbers to a Text File
