I want to change the value of my xml "abc.xml" element to the value that is stored in the variable $value i.e
$value = 'abc';
<annotation>
<filename>img_000001016592.png</filename>
<folder>Rec_20121219_171905</folder>
<source>
<sourceImage>The MIT-CSAIL database of objects and scenes</sourceImage>
<sourceAnnotation>LabelMe Webtool</sourceAnnotation>
</source>
<imagesize>
<nrows>481</nrows>
<ncols>640</ncols>
</imagesize>
</annotation>
The shell script is required which has one variable and it contains the value in the variable and then change the value of the element filename of the abc.xml to the value in variable.
Perhaps you mean to use sed.
value='abc'
sed -i "s|abc.txt|$value|g" abc.xml
You would have to run that in a shell, or as a shell script with the header #!/bin/sh
.
---- Update ----
#!/bin/sh
value="something"
sed -i "s|\(<filename>\)[^<>]*\(</filename>\)|\1${value}\2|" abc.xml
Add g
to the sed command if you need to replace multiple instances in one line.
sed -i "s|\(<filename>\)[^<>]*\(</filename>\)|\1${value}\2|g" abc.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With