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.

  • 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

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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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