LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sed / awk command to print line number as column? (https://www.linuxquestions.org/questions/linux-newbie-8/sed-awk-command-to-print-line-number-as-column-521661/)

johnpaulodonnell 01-22-2007 06:44 AM

sed / awk command to print line number as column?
 
Hi.

I have a data file containing say 10 columns. I'd like to add a column in the first column position to act as a label - just a column of line numbers. Does anyone know a simple sed / awk command to do this?

Thanks

zulfilee 01-22-2007 06:51 AM

$ awk '{print NR,$0}' <filename>

This will print the line number along with each field

A easier command will be

$ nl filename

[Or do u want the column numbers on top ? ]

- zulfi

johnpaulodonnell 01-22-2007 07:07 AM

That's perfect.

Thank you.


All times are GMT -5. The time now is 10:32 PM.