Reputation: 2543
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.
Upvotes: 2
Views: 114
Reputation: 88949
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>
Upvotes: 4