0

in bash, i'm trying to use sed to replace a line of text in xml file.

line_item=jdbc:a_connector://localhost:2323/database?create=true&ampssl=true&ampsslMode=required

In the xml file, I have it something like:

...
<property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>{URL_TO_CHANGE}</value>
</property>
...

I tried to do sed -e "s {URL_TO_CHANGE} $line_item " path/to/file.xml note: using (space) as the delimiter

however, the results is always: jdbc:a_connector://localhost:2323/database?create=trueURL_TO_CHANGEamp;ssl=trueURL_TO_CHANGEamp;

not sure why this is happening?

tripleee
  • 175,061
  • 34
  • 275
  • 318
jake wong
  • 4,909
  • 12
  • 42
  • 85
  • 1
    Please [Don't Parse XML/HTML With Regex.](https://stackoverflow.com/a/1732454/3776858) I suggest to use an XML/HTML parser (xmlstarlet, xmllint ...). – Cyrus Mar 21 '23 at 17:51
  • 1
    You have to escape the `&` in the replacement because it means "recall the text which matched" to `sed`. Similarly, you'd need to backslash-escape any backslashes in the subtitution. – tripleee Mar 21 '23 at 18:18

0 Answers0