Advertisement

04.15.2008 at 09:50AM PDT, ID: 23324368
[x]
Attachment Details

Help with a SED script to replace data in XML file

Asked by jrram in Shell Scripting, Linux

Tags: Linux, Shell Scripting, SED

Good afternoon all,

Please look at the example xml file below.  I am trying to replace and <indicator> if it exists in a certain <frame>.  I know its possible to do this with SED, but I don't have my mind wrapped around the SED control and loop statements well enough to write it.  Below is how I thought it should work written in loose Linux if statements.

TABLENAME="QUOTA_2"
INDICATOR="IND_02"

Read in a line
If (the line equals <frame>),
then
        read in the next line
        If (this next line equals $TABLENAME)
        then
                read in the next line.
                If (this next contains $INDICATOR)***
                then
                        Perform a substitution
                        End the cycle.
                else
                        Read in the next line and,
                        Keep looping back to *** to perform the check.
                        If </frame> is found and match never found. End the cycle.
                fi
        else
        start a new cycle.
        fi
else
        start a new cycle
fi

For example, how can I replace the <indicator id="IND_01"> to be <indicator id="IND_01" mode="off"> in the frame where the name is QUOTA_2.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
<!--QUOTA_1-->
<frame>
 <name>QUOTA_1</name>
 <entity>
    <name>1</name>
    <alias>2</alias>
    <expr>3</expr>
 </entity>
 <indicator id="IND_01">
    <summary>my summary</summary>
    <description>my address</description>
    <expr>my expression</expr>
    <conf>0.5</conf>
 </indicator>
 <indicator id="IND_02">
    <summary>Fish</summary>
    <description>Pork</description>
    <expr>Beef</expr>
    <conf>3.45</conf>
 </indicator>
</frame>
<!--QUOTA_2-->
<frame>
 <name>QUOTA_2</name>
 <entity>
    <name>1</name>
    <alias>2</alias>
    <expr>3</expr>
 </entity>
 <indicator id="IND_01">
    <summary>my summary</summary>
    <description>my address</description>
    <expr>my expression</expr>
    <conf>0.5</conf>
 </indicator>
 <indicator id="IND_02">
    <summary>Apple</summary>
    <description>Oranges</description>
    <expr>Peaches</expr>
    <conf>10.50</conf>
 </indicator>
 <indicator id="IND_03">
    <summary>Safety</summary>
    <description>Power</description>
    <expr>Freedom</expr>
    <conf>0.50</conf>
 </indicator>
</frame>
 
Keywords: Help with a SED script to replace data i…
 
Loading Advertisement...
 
[+][-]04.15.2008 at 02:39PM PDT, ID: 21363089

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 06:19PM PDT, ID: 21364066

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 05:37AM PDT, ID: 21400952

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:04AM PDT, ID: 21403811

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:14AM PDT, ID: 21403916

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Shell Scripting, Linux
Tags: Linux, Shell Scripting, SED
Sign Up Now!
Solution Provided By: ozo
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.21.2008 at 10:42AM PDT, ID: 21404192

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:56AM PDT, ID: 21404343

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 01:36PM PDT, ID: 21405751

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628