Use this command to add line numbers to a text file…
sed = filename.txt | sed 'N;s/\n/\t/' > filename_number.txt
This entry was posted
on Tuesday, July 7th, 2009 at 11:50 pm and is filed under Command Line, Linux.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
The thing is – I don’t know either. I get the command from various sources – and if I find them useful, I post it here. Only if I need to change its working do I spend time to study it. I suggest you take a look at the manual pages – you’ll get it.
July 16th, 2009 23:35
could you kindly break down the ‘N;s/\n/\t/’ part … i understand you want to substitute \n with \t … what is the N; there for ?
thanks in advance
July 17th, 2009 00:07
The thing is – I don’t know either. I get the command from various sources – and if I find them useful, I post it here. Only if I need to change its working do I spend time to study it. I suggest you take a look at the manual pages – you’ll get it.
August 30th, 2009 04:43
As an easier alternative, you could also use “cat” with the “n” flag.
cat -n filename > filename_number.txt