How can I append a line number and tab to the beginning of each line of a text file?
feedback
|
| |||||||||
feedback
|
|
The nl command should do this, but it adds space before the line number too. It's part of Linux coreutils.
| |||
|
feedback
|
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. | |||
feedback
|
cat -n adds linenumbers as " 123 linecontents" and that regexp modifies it to "linenumberTABlinecontents" | |||
|
feedback
|
or
| |||
|
feedback
|
|
Ok, since we are collecting ways to do this,
| |||||||
feedback
|
or for some non-GNU
| |||||||||||
feedback
|
|
How about
? | |||||||||
feedback
|