![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
awk try
Code:
awk '{ printf("%s (%s)\n",$0,NR-1) }' filename
|
|
#3
|
|||
|
|||
|
Code:
awk ' { print $0 " (" NR-1 ")"}' fl
|
|
#4
|
|||
|
|||
|
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
|
|||
|
|||
|
a sed try
Code:
sed = filename | sed -e 'N;s/\n/ /' -e 's/\(^[0-9][0-9]* \)\(.*$\)/\2 \( \1\)/g' |
|
#6
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |