Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-22-2007, 06:44 AM   #1
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Rep: Reputation: 15
sed / awk command to print line number as column?


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?

Old 01-22-2007, 06:51 AM   #2
Registered: Apr 2004
Location: India
Distribution: Redhat,Fedora
Posts: 430

Rep: Reputation: 39
$ 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
Old 01-22-2007, 07:07 AM   #3
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

Original Poster
Rep: Reputation: 15
That's perfect.

Thank you.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to strip words from front of line. sed/awk/grep? joadoor Linux - Software 6 08-28-2006 04:39 AM
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 09:09 PM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 11:13 AM
Print line number X of a file (in shell) rheza Programming 4 01-04-2005 05:55 PM
Quick Q: Command to print line number X? KneeLess Linux - Software 1 05-27-2004 07:49 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:49 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration