Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


<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
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


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.