LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 04-19-2009, 11:39 AM   #1
senthilmuthiah
Member
 
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Rep: Reputation: 16
Question 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..!
 
Old 04-20-2009, 04:38 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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.
 
  


Reply

Tags
children, extract, modify, parsing, specific, xml


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mp3 filename to xml shell script jason7 Linux - Server 1 03-21-2009 05:22 AM
Shell script to grep log for a specific error sfcg Programming 8 06-28-2008 09:12 AM
Shell script for modifying file extensions VTGuitarMan Linux - Newbie 6 03-08-2008 07:24 PM
How to remove single-line XML nodes from files dfrechet Programming 1 10-11-2005 02:00 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 01:39 PM


All times are GMT -5. The time now is 07:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration