-2

I have an xml file with a line: <includes>xyz</includes>

I have to append a value to xyz like <includes>xyz abc/v1.2.3</includes>

The value abc/v1.2.3 is stored in a variable: stringReplace="abc/1.2.3"

I am trying to achieve the same using sed:

sed -i -e "s/<includes>xyz<\/includes>/<includes>xyz\ $stringReplace<\/includes>/g" localConfig.xml

However, I am getting "sed: -e expression #1, char 41: unknown option to `s'".

Please help or any other way of doing it.

Nishant Kansal
  • 501
  • 1
  • 10
  • 23
  • 2
    Does this answer your question? [sed fails with "unknown option to \`s'" error](https://stackoverflow.com/questions/9366816/sed-fails-with-unknown-option-to-s-error) – Ryszard Czech Sep 07 '20 at 20:55

1 Answers1

2

If you have a slash / in the variable or file then use different separator (here i used | )

 sed -i -e "s|<includes>xyz</includes>|<includes>xyz $stringReplace</includes>|g" localConfig.xml
redInk
  • 699
  • 5
  • 11