Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using variables in a sed command – sed -e exception: unknown option to `s'

Lets say we have two variables

var1='<tr><th>Text</th><tr>
var2='<tr><th>Text</th><td>No applications<td><tr>'

if first(var1) text part is available in my file I want to replace it with second (var2) text part.

The command I have written is

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sed -i -e "s/$var1/$var2/g" mypage.html

this does not work and give an error message saying "- sed -e exception: unknown option to `s’ "
I tried removing the -e part. It also not works

How can I do this ?

>Solution :

The problem is that the separator that you give to s, namely /, also occurs in $var1 and $var2. Simply choose a different separator that doesn’t occur in these variables, for example |:

sed -i -e "s|$var1|$var2|g" mypage.html
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading