Pulling data from xml


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pulling data from xml
# 1  
Old 04-02-2013
Linux Pulling data from xml

Hi there, Please could anyone help with this.
I have an xml file that contains repeating values eg

Code:
<Rule name> AAAAA
<Action> BBBBB
</Action>
<Data> CCCCC
</Data>
<Type> DDDDD
</Type>
</Rule name>

<Rule name> A1A1A1A1
<Action> B1B1B1B1
</Action>
<Data> C1C1C1C
</Data>
<Type> D1D1D1D
</Type>
<Rule> Do this 
</Rule>
</Rule name>

And this repeats throughout the xml many times but the values between <Rule name> and </Rule name> varies there could be more or less xml values but I want all data between <Rule name> and </Rule name>. Rule name repeates many times throughout the file and I would like to pull all if poss
I have been using Sed but not with much luck, Any help would be much appreciated
can use sed, Awk, Perl or if you think better something else
many thanks Regards

Last edited by Scrutinizer; 04-02-2013 at 05:20 PM.. Reason: code tags
# 2  
Old 04-02-2013
What output do you want from this input? Show it, don't describe it.

There's many ways.

Please post an unabridged, unprettied-up section of your XML. Otherwise we're liable to make solutions that work for what you posted but don't work for your actual data.
# 3  
Old 04-03-2013
Hi There many thanks for getting back so quick to me, Sorry I had not explained it all out,
I have many xml files in format like below
the blocks I am interested in are

Code:
<ProfileDetails name="TEST">
<Rule name="COMBINED1 " enabled="true" terminalState="false" evaluateOrder="1">
<Condition>true</Condition>
<Actions>
<Action name="TESTRun" type="add" evaluateOrder="1">
<Condition>true</Condition>
<Result type="true" tags="TEST">"FULL"</Result>
</Action>
</Actions>
</Rule>

<Session>
<Name>EVENT</Name>
<StartTime>#{timestart}</StartTime>
<StopTime>#{timestop}</StopTime>
<Type>ion</Type>
<Trace>true</Trace>
<Allow>true</Allow>
<Inbound>Run5 </Inbounds
<Outbound>Run6</Outbound>
<Session1>
<In>TEST1IN</In>
<Out>"TEST1OUT"</Out>
<load> STRIP</load>
<coder>code1</coder>
</Session1>
</Session>

<Rule name="COMBINED2" enabled="true" terminal="false" evaluateOrder="20">
<Condition>regexp(${run}, "(P)")</Condition>
<Actions>
<Action name="TESTstop " type="add" evaluateOrder="1">
<Condition>true</Condition>
<Result type="true" tags="Red”</Result> 
</Action>
</Actions>
</Rule>

<Route name="EVENT" enabled="false">
<Keys>
<Key>cond( isdef(${"STOP"}), strcat("STOP_", ${"3"}), "");</Key>
<Key>cond( isdef(${"START"}), strcat("START_", ${"4"}), "");</Key>
</Keys>
<Destinations>
<Destination role="source" name="EVENT"/>
</Destinations>
</ProfileDetails>

And the desired output would be as above highlighted in red only
Please note that there are many Rules and /Rules blocks within the xml and I would like just these blocks and not any other blocks if poss

Many thanks in advance

Last edited by Scrutinizer; 04-03-2013 at 04:59 PM.. Reason: code tags / formatting of calabri font forest
# 4  
Old 04-03-2013
If that's really what it looks like awk should be able to extract those sections easily enough by looking for <Rule and </Rule:

Code:
awk '/<Rule/ { N++ } N; /<\/Rule/ { N-- }' inputfile > outputfile

This User Gave Thanks to Corona688 For This Post:
# 5  
Old 04-03-2013
Hey Many thanks that worked a treat Really appreciated Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pulling information from a data file by date

awk -v now="$(date +%s)" -v tDiff="${USERMINUTES}" ' BEGIN { FS="=" if (!now) now=systime() if (!tDiff) tDiff=60*60 p=1 } /{/ {rec=$0;p=1;next} /}/ && rec && p {print rec ORS $0;next} $1=="entry_time" { if (now-$2>tDiff)p=0 } {rec=rec ORS $0}'... (6 Replies)
Discussion started by: SkySmart
6 Replies

2. Shell Programming and Scripting

Pulling Data, Then Moving to the Next File

I'm scanning a list of emails- I need to pull 2 pieces of data, then move to the next file: Sender's Email Address Email Date I need these to be outputted into a single column- separated by a ",". Like this: Email1's Address, Email1's Date Stamp Email2's Address, Email2's Date Stamp... (4 Replies)
Discussion started by: sudo
4 Replies

3. Shell Programming and Scripting

BASH- Need help pulling data from .emlx

Hello, fellow computer junkies. First time poster! My boss wrote an application (Mavericks 10.9, Mountain Lion 10.8) that checks a user's security settings. The user runs the application, then it spits out an email that is sent back to our inbox showing the results. On our end, we have a mail rule... (5 Replies)
Discussion started by: sudo
5 Replies

4. Shell Programming and Scripting

Pulling data by GPS coordinates from text file

Hi there, I'm having a problem trying to extract data from within a text file. I'm trying to extract this manually for a lack of better words. I need any items that fall within latitude 36.5 to 39.5 and long -75.3 to -83.9 I have been doing this using cat neta.txt | grep '!38' and working... (6 Replies)
Discussion started by: Mikey
6 Replies

5. Shell Programming and Scripting

Help with pulling / filtering data from a .csv

Good day Gurus, I have a csv file that contains an inventory of active servers. This csv file contains a well over a hundred systems (IBM, SUN, HP). It also contains those systems details. See below for an example hostA,invver,1.02,20100430 hostA,date,08/30/2010,06:18 hostA,use,"Unknown... (4 Replies)
Discussion started by: LuffyDMonkey
4 Replies

6. Shell Programming and Scripting

SFTP to server, pulling data and removing the data

Hi all, I have the following script, but are not too sure about the syntax to complete the script. In essence, the script must connect to a SFTP server at a client site with username and password located in a file on my server. Then change to the appropriate directory. Pull the data to the... (1 Reply)
Discussion started by: codenjanod
1 Replies

7. Shell Programming and Scripting

Pulling data from a standard comment block - perl

OK so I've inherited a set of scripts that do some work on a database. They do all have a standard comment block at the beginning that has good information on the script. I would like to generate a quick web page report that lists the script name and the description lines (for now it may be... (1 Reply)
Discussion started by: khuilman
1 Replies

8. Shell Programming and Scripting

Pulling data and following lines from file

I saw a few posts close to what i want to do, but they didn't look like they would work exactly.. or I need to think out of the box on this. I have a file that I keep server stats in for my own performance analysis. this file has the output from many commands in it (uptime, vmstats, ps, swap... (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question