LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Modifying Specific Child Nodes In XML using Shell Script (https://www.linuxquestions.org/questions/linux-newbie-8/modifying-specific-child-nodes-in-xml-using-shell-script-720214/)

senthilmuthiah 04-19-2009 11:39 AM

Modifying Specific Child Nodes In XML using Shell Script
 
All:

I have an xml file which is as follows:
-<tns:System xsi:..........>
<tns:Sol tmp......>

<tns:a>
...
</tns:a>

<tns:bst>
....
</tns:bst>

<tns:bsint>
<tns:bst name="bst0a">
<tns:Tim name="bst0b" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst0b">
<tns:Tim name="bst0a" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst0c">
<tns:Tim name="bst0d" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst0d">
<tns:Tim name="bst0e" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>

</tns:bst>
<tns:bst name="bst0f">
<tns:Tim name="bst1a" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
<tns:Tim name="bst1b" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
<tns:Tim name="bst1c" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>]
<tns:Tim name="bst1d" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst1a">
<tns:Tim name="bst0f" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst1b">
<tns:Tim name="bst0f" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst1c">
<tns:Tim name="bst0f" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>
<tns:bst name="bst1d">
<tns:Tim name="bst0f" biTim="1E5" brTim="1E-3"
fstBindTime="0.00000000001"/>
</tns:bst>

</tns:bsint>
<tns:d>
---
</tns:d>
...
..
</tns:System>


In this xml file, I would like to change the values of biTim only. All the biTim corresponding to bst0a till bst0e (colored orange) should be given one value while all the biTim in the next set (colored yellow) should be given another value.

I know this should be possible through sed/awk. However, I am not able to figure it out. I would be more than pleased if somebody could help.

Thank you very much in advance..!

jschiwal 04-20-2009 04:38 AM

The yellow on blue is unreadable.

For processing xml files you might want to look at the xsltproc program.

Code:

sed '/bst0a/,/bst0e/s/brTim=".*"/brTim="something_else"/' testfile
If the bst0<letter> patterns are in order and brTim= is contained within the range, then you can use sed easily.
The slashes before the s command select a range of lines based on a regex pattern. You can also use 1,/bst0e/ as well to start the range on the first line.


All times are GMT -5. The time now is 06:01 AM.