Posted in Command Line, Linux Add Line Numbers Binny V A July 7, 2009 3 Comments on Add Line Numbers Use this command to add line numbers to a text file… sed = filename.txt | sed 'N;s/\n/\t/' > filename_number.txt Author: Binny V AA philosopher programmer who specializes in backend development and stoicism.
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 Reply
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. Reply
As an easier alternative, you could also use “cat” with the “n” flag. cat -n filename > filename_number.txt Reply
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
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.
As an easier alternative, you could also use “cat” with the “n” flag.
cat -n filename > filename_number.txt