Friday, 15 August 2014

Update xml attribute using sed (Windows + cygwin and Linux)?



I need to make an update on an xml file using a sed command and I'm having trouble with this one.. the it needs to run on both Windows (using cygwin) and Linux.


The XML has the following element:



...

<parameter name="jersey.test.host" value="localhost" />

...


I need to update the value to an arbitrary value, say, "abc".


I tried several commands such as:



sed -i "s#\(jersey.test.host\)\s*value="\(.*\)" />$#\1abc#" "C:\file.xml"


and also:



sed -i "s#<parameter name="jersey.test.host" value=".*" />#<parameter name="jersey.test.host" value="abc" />#"" "C:\file.xml"


But no changes are performed to the file when I run the command, which I bet means I'm not matching correctly.


I would not mind if I could do this using awk as well. Whatever works, as long as the same command can be used in both Windows + Cygwin and Linux.


Can anyone help me out with this one? Any pointers are greatly appreciated!


Thanks!


No comments:

Post a Comment