The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
insert a line after specific line namishtiwari Shell Programming and Scripting 8 05-21-2008 11:16 AM
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 05:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 07:19 AM
sed/awk to insert comment at defined line number homefp Shell Programming and Scripting 8 01-18-2008 01:14 PM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-08-2005 10:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-25-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
how to insert a line number on every line

hi...

i have a file with data and would like to insert a number and bracket 1) ...2)
at the beginning of every successive line; to add some formatting to the text
Reply With Quote
Forum Sponsor
  #2  
Old 03-25-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
its ok i have solved it......

grep $USER file>> newfile
sed = file3 | sed 'N;s/\n/\)/' # this prints number for every line....with a very nice right bracket ie 1)...
2)...

thanks for all your help
i would be lost with out it....

thanks
Reply With Quote
  #3  
Old 03-25-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,614
Thanks for posting your solution. It is an interesting approach. Another way is to use the nl command. nl numbers lines for a living. Just doing "nl file3" won't exactly replicate the result you got with your sed processes though. First, by default, nl ignores blank lines and only numbers lines with text on them. But a "-ba" option will fix that. The next problem is that nl keeps the line number right justified inside a field that is 6 characters wide. I like that feature, although 6 is a bit much. To emulate your result of not aligning the line numbers we can set the field width to 1. And finally, nl puts a tab after the line number, and we need to change that to a right parenthesis. So:
nl -ba -w1 -s\) file3
will do what you want. There are also a lot of other options to control the output.
Reply With Quote
  #4  
Old 03-25-2006
Registered User
 

Join Date: Mar 2006
Posts: 14
Thanks perder
that was really helpful

i prefer the quicker solutions
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0