Number a list at end of line using 'sed'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Number a list at end of line using 'sed'
# 1  
Old 09-13-2006
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
# 2  
Old 09-13-2006
awk try

Code:
awk '{ printf("%s (%s)\n",$0,NR-1) }' filename

# 3  
Old 09-13-2006
Code:
awk ' { print $0 " (" NR-1 ")"}' fl

# 4  
Old 09-13-2006
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
# 5  
Old 09-13-2006
a sed try

Code:
sed = filename | sed -e 'N;s/\n/  /' -e 's/\(^[0-9][0-9]* \)\(.*$\)/\2 \( \1\)/g'

# 6  
Old 09-13-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

I need to find in a file a list of number where last two digit end in a range

I all I am tryng to find a way to sort a list of number in a file by the value of last two digit. i have a list like this 313202320388 333202171199 373202164587 393202143736 323202132208 353201918107 343201887399 363201810249 333201805043 353201791691 (7 Replies)
Discussion started by: rattoeur
7 Replies

2. Shell Programming and Scripting

Search from a line to end of list using sed

Dear Unix Experts :), Below is a small section of a large file with the following list: 1. Starts with string " interest" as the heading 2. Followed by a list of activities 3. Ends with a blank line before starting with another different list. E.g. Sporting interest football... (13 Replies)
Discussion started by: gjackson123
13 Replies

3. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

4. Shell Programming and Scripting

adding line number to *end* of records in file

Given a file like this: abc def ghi I need to get to somestandardtext abc1 morestandardtext somestandardtext def2 morestandardtext somestandardtext ghi3 morestandardtext Notice that in addition to the standard text there is the line number added in as well. What I conceived is... (4 Replies)
Discussion started by: edstevens
4 Replies

5. Shell Programming and Scripting

AWK-grep from line number to the end of file

Does anyone know how to use awk to act like grep from a particular line number to the end of file? I am using Solaris 10 and I don't have any GNU products installed. Say I want to print all occurrences of red starting at line 3 to the end of file. EXAMPLE FILE: red green red red... (1 Reply)
Discussion started by: thibodc
1 Replies

6. Shell Programming and Scripting

sed issue with end of line

Example, Trying to replace text to the end of a line. Text file looks like this PP= 4 PP= 412 PP= 425 I want to replace only the following line: PP= 4 with PP= 2 How can this be done with sed? (3 Replies)
Discussion started by: hanson397
3 Replies

7. Shell Programming and Scripting

To add a number at the end of the line

Hi Folks, Using the Vi, how can I add a numbers at the end of the line. For eg: I have the numbers in the file as: 58.125.33 22.58.68 25.144.225 114.25.38 I need to add .0/8 at the end of all the line. So, it should be like 58.125.33.0/8 22.58.68.0/8 25.144.225.0/8 114.25.38.0/8 (6 Replies)
Discussion started by: gsiva
6 Replies

8. Shell Programming and Scripting

Capturing a number at the end of line and store it as variable

Hello, Would someone guide me on how to write a shell script the would search for a phone no using at the end text file using sed or awk and store it in a varaible or print it. The text file is in this form text or numbers in first line text or numbers in second line . . . Firsname... (6 Replies)
Discussion started by: amuthiga
6 Replies

9. Shell Programming and Scripting

Select matches between line number and end of file?

Hi Guys/Gals, I have a log file that is updated once every few seconds and I am looking for a way to speed up one of my scripts. Basically what I am trying to do is grep through a text file from start to finish once. Then each subsequent grep starts at the last line of the previous grep to... (4 Replies)
Discussion started by: Jerrad
4 Replies

10. UNIX for Dummies Questions & Answers

sed to end of line

I know this is going to be an easy anwer, but I haven't been able to figure this out - even with the help of the previous posts. I want to go from this PROD USER anon; to this TEST; I have coded a few sed commands, and none of them are getting the job done. anon will not always be the... (2 Replies)
Discussion started by: djschmitt
2 Replies
Login or Register to Ask a Question