LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 15
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
 
Old 01-22-2007, 07:51 AM   #2
zulfilee
Member
 
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, 08:07 AM   #3
johnpaulodonnell
Member
 
Registered: Jun 2006
Location: Galway
Distribution: Suse 10.1
Posts: 114

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

Thank you.
 
  


Reply


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 05:39 AM
Awk command-line arguments lowpro2k3 Programming 1 03-28-2005 10:09 PM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 12:13 PM
Print line number X of a file (in shell) rheza Programming 4 01-04-2005 06:55 PM
Quick Q: Command to print line number X? KneeLess Linux - Software 1 05-27-2004 08:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:13 AM.

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