Intro
Prefixing lines with their respective line number in a text file using a Microsoft Windows Operating System... I've just googled this as I couldn't remember how I did this last time and a number of people showing off their MS-DOS batch skills have proposed stupid extensive solutions when all you need is one command-line.


Why?
Working with programming languages, I often need to write the accompanying documentation. Within the documentation, I may want to refer to a line of code within a text file. I also find myself copying amounts of code into the same document and then needing lines prefixed so that I can explain the code.


What?
Change contents of "original_file.txt"

The first line of my code
The second line of my code
The third line of my code
To "results_file.txt"
  1:  The first line of my code
  2:  The second line of my code
  3:  The third line of my code


How?

Subcategories