Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-19-2009, 12:39 PM   #1
Registered: Mar 2009
Distribution: Ubuntu, Fedora
Posts: 56

Rep: Reputation: 16
Question Modifying Specific Child Nodes In XML using Shell Script


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



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

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


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, 05:38 AM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
The yellow on blue is unreadable.

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

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.


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 06:22 AM
Shell script to grep log for a specific error sfcg Programming 8 06-28-2008 10:12 AM
Shell script for modifying file extensions VTGuitarMan Linux - Newbie 6 03-08-2008 08:24 PM
How to remove single-line XML nodes from files dfrechet Programming 1 10-11-2005 03:00 PM
Shell script - how to show a specific line of a text file davi_cabral Linux - Software 3 09-28-2004 02:39 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:31 PM.

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