Results 1 to 5 of 5
i need to parse the following output and get all the lines representing a particular row
the output is :
<resultSet>
<row>
<column xsi:type="Key">
<id>145</id>
<policy className="Meter" id="144"/>
<name>key1</name>
<description>key</description>
...
- 03-23-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 14
parsing output
i need to parse the following output and get all the lines representing a particular row
the output is :
<resultSet>
<row>
<column xsi:type="Key">
<id>145</id>
<policy className="Meter" id="144"/>
<name>key1</name>
<description>key</description>
<type>SESSION</type>
</column>
</row>
<row>
<column xsi:type="Key">
<id>150</id>
<policy className="Meter" id="149"/>
<name>key2</name>
<description>first key</description>
<type>SESSION</type>
</column>
</row>
</resultSet>
Now I need to get the row based on the <id>
So I know the id say 145, now I need to print out all the elements in that row.
Please help me out with this.I need to do this in shell script
Thanks in advance
- 03-23-2010 #2
Sounds like a homework problem - "I need to do this in shell script"
Make mine Arch Linux
- 03-23-2010 #3Just Joined!
- Join Date
- Feb 2010
- Posts
- 14
do u have an idea on how to do it?
- 03-23-2010 #4
what language you gonna write it in?
linux user # 503963
- 03-23-2010 #5Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
After looking at your previous posts, you don't seem to be a guy doing homeworks.
The following script is not a general purpose xml bash parser, it just does what you want. C++/C, Java... have got full XML processors and parsers for real flexibility and productivity.
The idea is to write all elements of a row on one line, then select the required line by the id tag, and finally present the data as in the original file.
Code:#!/bin/bash IN="/var/tmp/xmlforbash.xml" OUT="/var/tmp/toRows.xml" rm -f "$OUT" row="" while read line do [ "$line" != "<resultSet>" ] && row="$row$line" if [ "$line" = "</row>" ]; then echo "$row" >> "$OUT" row="" fi done < "$IN" grep "<id>145</id>" "$OUT" | sed 's/></>\n</g' #rm -f "$OUT"0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.


Reply With Quote