Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have got another problem here with SED. I wanna add some text to a string but with out changing a particular word which varies with every line. Or wrap a code on a string keeping it as it is.

Example : FROM

<font color="#000000"><p align="JUSTIFY">COAT. how are you.
<font color="#000000"><p align="JUSTIFY">MONEY.Where are you.
<font color="#000000"><p align="JUSTIFY">FOOD.what are you.
<font color="#000000"><p align="JUSTIFY">CAR.which are you.
<font color="#000000"><p align="JUSTIFY">QUALITY.When are you.

TO

<b><font color="#000000"><p align="JUSTIFY">COAT.</b>how are you.
<b><font color="#000000"><p align="JUSTIFY">MONEY.</b>Where are you.
<b><font color="#000000"><p align="JUSTIFY">FOOD.</b>what are you.
<b><font color="#000000"><p align="JUSTIFY">CAR.</b>which are you.
<b><font color="#000000"><p align="JUSTIFY">QUALITY.</b>When are you.

Again thanks in advance. Regards.

share|improve this question
    
You want to add before how, where, what, which, when? –  thefourtheye May 3 '13 at 17:34
    
No i want to add after the dot "." –  22lk94k943 only May 4 '13 at 7:05
    
Updated the answer. Please check –  thefourtheye May 4 '13 at 7:12
    
Is there any problem if we have more dots in a line? just going to give it a try, Thanks –  22lk94k943 only May 4 '13 at 7:42
    
'<font color="#000000"><p align="JUSTIFY">COAT.</b>hg;kjhkh;kjnkjh <font color="#000000"><p align="JUSTIFY">MONEY.</b>kjhkjgkjbkj <font color="#000000"><p align="JUSTIFY">FOOD.</b>jhgkjhkjh <font color="#000000"><p align="JUSTIFY">CAR.</b>kjblkjbkjb <font color="#000000"><p align="JUSTIFY">QUALITY.</b>kjbhkjbjhb' No <b> at beginning. –  22lk94k943 only May 4 '13 at 7:49

1 Answer 1

up vote 2 down vote accepted

sed 's/\./\0<\/b>/g' < FileName

It finds all occurances of "." and replaces it with "."

sed 's/\.$/\0<\/b>/' < FileName

It finds the occurances of "." at the end of line and replaces it with "."

(sed 's/\.$/\0<\/b>/' | sed 's/^/\0<b>/') < FileName

It finds the occurances of "." at the end of line and replaces it with "." and appends "" at the beginning

share|improve this answer
    
Sorry but there are other words and its not the end i am going to change the question a bit sorry for trouble. –  22lk94k943 only May 3 '13 at 17:31
    
Ya i saw it is appending </b> after the end "." not at the first dot. I mean to say i want to append it after the first "." and not any other in that line. Yet again changing my question a bit again. –  22lk94k943 only May 4 '13 at 11:26
    
Got it bro just removed the "$" from the first command and it is working fine. Answer : (sed 's/\./\0<\/b>/' | sed 's/^/\0<b>/') –  22lk94k943 only May 4 '13 at 11:33
    
Thank you very much @thefourtheye –  22lk94k943 only May 4 '13 at 11:35
    
You are welcome :) –  thefourtheye May 4 '13 at 11:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.