![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
Thanks perder
that was really helpful i prefer the quicker solutions |
|||
| Google The UNIX and Linux Forums |