Add/remove xml tags using a bash script.

Posted by sixtyfootersdude on Stack Overflow See other posts from Stack Overflow or by sixtyfootersdude
Published on 2010-04-01T16:27:44Z Indexed on 2010/04/01 16:33 UTC
Read the original article Hit count: 494

Filed under:
|
|

I have an xml file that I want to configure using a bash script. For example if I had this xml:

<a>

  <b>
    <bb>
        <yyy>
            Bla 
        </yyy>
    </bb>
  </b>

  <c>
    <cc>
      Something
    </cc>
  </c>

  <d>
    bla
  </d>
</a>

(confidential info removed)

I would like to write a bash script that will remove section <b> (or comment it) but keep the rest of the xml intact. I am pretty new the the whole scripting thing. I was wondering if anyone could give me a hint as to what I should look into.

I was thinking that sed could be used except sed is a line editor. I think it would be easy to remove the <b> tags however I am unsure if sed would be able to remove all the text between the <b> tags.

I will also need to write a script to add back the deleted section.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about bash