Extract value from XML


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract value from XML
# 8  
Old 01-06-2012
you know mi, I tried the same for first one which goes like this and working fine.

Code:
awk '/displayName/ && $2~/^[0-9][0-9]-/{dt[++cnt]=$2}
> /^formattedValue>/{fv=$2; getline;
> if ( dt[$2] == "" ){
>  print "==================================="
> print "TotalValue", fv,$2
>  print "===================================" }
> else
> { cnt=split( dt[$2], a, "-")
> { name=a[3]a[2]a[1] }
> print name,fv,$2
> }name=""}' FS="[><]" RS='><' output.txt
===================================
TotalValue 1721994 0
===================================
20120105 1141169 1
20120104 580825 2

but for the second one (which is more good way represnting it), I was thinking if spliting it into array and then join it thru for loop getting the value from that array rather than joining thru their hardcoded value. There I went crazy but thanks anyway.
# 9  
Old 01-06-2012
Ever used command xmllint and trying xpath in that. Should be able to extract any thing from XML.
# 10  
Old 01-08-2012
Not a good solution as compared to awk

Code:
( cat XMLFILE|tr '>' '\012'|egrep  "</formattedValue$"|cut -d "<" -f1 >FILE1 ;cat XMLFILE|tr '>' '\012'|egrep  "</displayName$"|cut -d "<" -f1 >FILE2;paste FILE1 FILE2|grep -- - ;rm FILE1 FILE2 )


FYI : I tried on RHE4 machine


Code:
$ cat display|tr '>' '\012'|egrep  "</displayName$"|cut -d "<" -f1 >displayName
$ cat display|tr '>' '\012'|egrep  "</formattedValue$"|cut -d "<" -f1 >formattedValue
$ paste displayName formattedValue|grep -- - ;rm displayName formattedValue
04-01-2012      444930
20-12-2011      1136654
12-12-2011      1081680
09-12-2011      1177505

---------- Post updated 01-08-12 at 12:23 AM ---------- Previous update was 01-07-12 at 11:25 PM ----------

@chakrapani : Can you please post the command ?
Tried but unable to get the required output .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a value from an xml file

I have this XML file format and all in one line: Fri Dec 23 00:14:52 2016 Logged Message:689|<?xml version="1.0" encoding="UTF-8"?><PORT_RESPONSE><HEADER><ORIGINATOR>XMG</ORIGINATOR><DESTINAT... (16 Replies)
Discussion started by: mrn6430
16 Replies

2. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

3. Shell Programming and Scripting

Extract a particular xml only from an xml jar file

Hi..need help on how to extract a particular xml file only from an xml jar file... thanks! (2 Replies)
Discussion started by: qwerty000
2 Replies

4. Shell Programming and Scripting

Extract string from XML

Hi, I wish to grep for the first instance of <listen-address> value between the first <server></server> tag in an xml file. Sample xml: ......... <timeout-seconds>1500</timeout-seconds> </jta> <server> <name>Adminserver_DEV</name> ... (9 Replies)
Discussion started by: mohtashims
9 Replies

5. Shell Programming and Scripting

xml extract problem

I have looked at other responses and never was able to modify to work. data is: <?xml version="1.0"?> <note version="0.3" xmlns:link="http://beatniksoftware.com/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size" xmlns="http://beatniksoftware.com/tomboy"><title>recoll</title><text... (12 Replies)
Discussion started by: Klasform
12 Replies

6. Shell Programming and Scripting

sed extract from xml

I have an xml file that generally looks like this: "<row><dnorpattern>02788920</dnorpattern><description/></row><row><dnorpattern>\+ 44146322XXXX</dnorpattern><description/></row><row><dnorpattern>40XXX</dnorpattern><description/></row><row><dnorpattern>11</dn... (4 Replies)
Discussion started by: garboon
4 Replies

7. Shell Programming and Scripting

XML data extract

Hi all, I have the following xml document : <HEADER><El1>asdf</El1> <El2>3</El2> <El3>asad</El3> <El4>asasdf</El4> <El5>asdf</El5> <El6>asdf</El6> <El7>asdf</El7> <El8>A</El8> <El9>0</El9> <El10>75291028141917</El10> <El11>asdf</El11> <El12>sdf</El12> <El13>er</El13> <El14><El15>asdf... (1 Reply)
Discussion started by: nthed
1 Replies

8. Shell Programming and Scripting

Extract xml data

Hi all, I have the following xml file : <xmlhead><xmlelement1>element1value</xmlelement1>\0a<xmlelement2>jjasd</xmlelement2>...</xmlhead> As you can see there are no lines or spaces seperating the elements, just the character \0a. How can i find and print the values of a specific element?... (1 Reply)
Discussion started by: nthed
1 Replies

9. Shell Programming and Scripting

SED extract XML value

I have the following string: <min-pool-size>2</min-pool-size> When I pipe the string into the following code I am expcting for it to return just the value "2", but its just reurning the whole string. Why?? sed -n '/<min-pool-size>/,/<\/min-pool-size>/p' Outputting:... (13 Replies)
Discussion started by: ArterialTool
13 Replies

10. Shell Programming and Scripting

· simerian · XML Extract

The script following in this thread allows XML data to be located and extracted in a variety of forms from an XML data stream. Using this utility, it is possible to extract all manner of XML subsets and allow data to be post inserted into the "original" XML at any logical point. The pipe is... (2 Replies)
Discussion started by: Simerian
2 Replies
Login or Register to Ask a Question