The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
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
How to 'sed' the middle line? g_jumpin Shell Programming and Scripting 7 11-08-2006 02:14 PM
Unix Script with line number at beginning of each line. mascorro Shell Programming and Scripting 5 06-19-2006 01:34 PM
identifying duplicates line & reporting their line number stresslog UNIX for Dummies Questions & Answers 5 04-23-2006 09:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-13-2006
Registered User
 

Join Date: Sep 2006
Posts: 8
Number a list at end of line using 'sed'

Hi All
I have a script which has produced a list, I have used 'sed' to number my list, but i want to list at end of line with the first line starting at zero (0) and brackets round it
ie
My List i want

Hello (0)
this (1)
day (2)
can (3)
be (4)

sed '/./=' filename | sed '/./N; s/\n/) /'

Result i am getting using above sed command
1)Hello
2)this
3)day

Thanks if you can sort it.
Any command will do.
Chassis
Reply With Quote
Forum Sponsor
  #2  
Old 09-13-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
awk try

Code:
awk '{ printf("%s (%s)\n",$0,NR-1) }' filename
Reply With Quote
  #3  
Old 09-13-2006
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
awk ' { print $0 " (" NR-1 ")"}' fl
Reply With Quote
  #4  
Old 09-13-2006
Registered User
 

Join Date: Sep 2006
Posts: 8
thats good

Thanx for the quick reply, it works, but when i use that it repeats my list adding the last line each time through the loop until it goes through what info i need to extract, so if my list is very large it will number it for ever.

ie

1
1
2
1
2
3
1
2
3
4
1
2
3
4
5
and so on

but i will play around with it, me and command 'awk' are not the best of friends...lol
Thank you
Chassis
Reply With Quote
  #5  
Old 09-13-2006
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
a sed try

Code:
sed = filename | sed -e 'N;s/\n/  /' -e 's/\(^[0-9][0-9]* \)\(.*$\)/\2 \( \1\)/g'
Reply With Quote
  #6  
Old 09-13-2006
Registered User
 

Join Date: Sep 2006
Posts: 8
perfect

Thanks guys
Yes the 'awk' did work (my fault) and so did the 'sed'

my 'done' went for a walk somewhere else, its now being grounded with no TV...lol

Cheers

Chassis
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:40 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