How can I append a line number and tab to the beginning of each line of a text file?
Tell me more
×
Super User is a question and answer site for
computer enthusiasts and power users. It's 100% free, no registration required.
|
|
|||||||||||
|
|
The nl command should do this, but it adds space before the line number too. It's part of Linux coreutils.
|
|||
|
The command "sed =" will print the line number followed by a carriage return and then the next line. The expression "N;s/\n/\t/" will take each line, get the next line (ie line number and the line), and replace the carriage return with a tab. |
|||
|
cat -n adds linenumbers as " 123 linecontents" and that regexp modifies it to "linenumberTABlinecontents" |
|||
|
|
|
Ok, since we are collecting ways to do this,
|
|||||
|
or for some non-GNU
|
|||||||||||
|
|
How about
? |
|||||||||
|