0

I have an xml file called test.xml.

<deathList>
<victimGroupA>
  <person1>
    <name>The Pope</name>
    <email>pope@vatican.gob.va</email>
    <is_satan>0</is_satan>
  </person1>
  <person2>
    <name>George Bush</name>
    <email>father@nwo.com</email>
    <is_satan>1</is_satan>
   </person2>
  <person3>
    <name>George Bush Jr</name>
    <email>son@nwo.com</email>
    <is_satan>0</is_satan>
  </person3>
</victimGroupA>
<victimGroupB>
  <person1>
    <name>bob</name>
    <email>bob@bobby.com</email>
    <is_satan>0</is_satan>
  </person1>
  <person2>
    <name>mike</name>
    <email>mike@michael.com</email>
    <is_satan>0</is_satan>
  </person2>
</victimGroupB>
<victimGroupC>
  <person1>
    <name>kenny</name>
    <email>kenny@youkilledkenny.com</email>
    <is_satan>0</is_satan>
  </person1>
</victimGroupC>
</deathList>

I want to write a bashrc script that will try to echo the following:

victimGroupA
person1
person2
person3
victimGroupB
person1
person2
victimGroupC
person1

Basically it should detect all victimGroup* and print out all the next sublevel categories of it. What's the easiest way of doing this? I need it compatible with centos and ubuntu.

daemoner119
  • 113
  • 1
  • 9
  • I was merely using some of his xml values for a test i wish to run. But i still do not know how to grab the "subcategory" of the xml. – daemoner119 Jul 12 '16 at 14:49
  • do you have to do it in shell script or you are willing to write some code... – vtd-xml-author Jul 12 '16 at 22:42
  • Once you have a reasonable understanding of XPath, this is definitely no longer a [tag:bash] question, and trying to use regex or other shell script approaches to parse XML is just misdirected, as massively demonstrated numerous times before. – tripleee Jul 27 '16 at 08:41

1 Answers1

1

You can try this;

egrep 'victim|person' test.xml | grep -v / | sed -e 's/\(<\)\|\(>\)\|\( \) //g'

Mustafa DOGRU
  • 3,994
  • 1
  • 16
  • 24