I am trying to replace string within quotes in a file! Here is an example :
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Manager pathname="" />
<Resource auth="Container" driverClassName="org.postgresql.Driver" maxActive="20" maxIdle="5" maxWait="10000" name="jdbc/custom" password="CHANGEIT" type="javax.sql.DataSource" url="jdbc:postgresql://10.10.10.10:5432/database" username="MyUser"/>
</Context>
This command works for several 'fields' but it doesn't work with username because of / .
# It's OK
sed 's/\(.*password=\)[^ ]*\( .*\)/\1"NEW_VALUE"\2/' ROOT.xml
# It's NOK
sed 's/\(.*username=\)[^ ]*\( .*\)/\1"NEW_VALUE"\2/' ROOT.xml
How can I do that please ?
Thank you,
Best Answer
You have to change the command
into
because
[^ ]
means: Every character except ablank
.[^ \/]
means: Every character except ablank
and/or/
.