2

I am (unsuccessfully) trying to substitute the database host entry in a Magento local.xml file (the connection string file).

The line is the following:

<host><![CDATA[localhost]]></host>

I want to find the line that contains "host" with sed and then replace the content of the inner brackets with something else.

Note - the content of the inner brackets won't always be "localhost", so s/localhost/lala/g won't work.

I got to the following:

sed -i "/\<host\>/s/.../lala/2" local.xml

Help please.

Neekoy
  • 2,325
  • 5
  • 29
  • 48

1 Answers1

4

With GNU sed:

sed 's|\(<host><!\[CDATA\[\).*\(\]\]></host>\)|\1lala\2|' file

or

sed -E 's|(<host><!\[CDATA\[).*(\]\]></host>)|\1lala\2|' file

Output:

<host><![CDATA[lala]]></host>
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Woah, thanks a lot. Switched to "sed -i" and it was replacing them perfectly. Thanks a lot for the lesson and info. – Neekoy Aug 30 '15 at 21:12