How to get values from xml tags?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get values from xml tags?
# 1  
Old 06-19-2012
How to get values from xml tags?

Hi guys,

Need ur help again.
Source File is coming like this. sample two records are below:
Code:
<?xml version="1.0"?>
<Object>
  <Header>
    <XCOMVers>V1.0</XCOMVers>
    <REPORT>XXXXX</REPORT>
    <CODE>002</CODE>
  </Header>
  <IssueCard>
    <Record>
	<L>CAR SYSTEM           -SSSSS  -</L>
      <L>                          CODE:      202</L>
      <L>---</L>
      <L>Message:</L>
      <L>:21:XXXXXXXX</L>
      <L>:103B:/1213-XX736472-567GH0</L>
      <L>---</L>
      <L>Confirm:</L>
      <L>---</L>
      <L>Data Log:</L>
      <L>Created:                     Status-ID:        R-NO:       Details:</L>
      <L>2010-03-25-09.51.52.484529   CREATED           ICG-SSTS   Message log step 1</L>
      <L>                                                          4545454555</L>
      <L>2010-03-25-09.51.52.509229   SENDER    ICG-SSTS   Message log step 2</L>
      <L>2010-03-25-09.51.52.520070   EXIT-SYSTEM  ICG-SSTS   Message log step 3</L>
      <L>                                                          Message log step 5</L>
      <L>2010-03-25-09.51.53.157416   EXIT-OK-SYSTEM    ICG-SSTS   Message log step 6</L>
      <L>                                                          Message log step 7</L>
      <L>2010-03-25-09.51.53.171452   COMPLETED         ICG-SSTS   Message log step 8</L>
      <L>                                                          Message log step 9</L>
      <L>                                                          Message log step 10</L>
      <L>---</L>
    </Record>
  </IssueCard>
</Object>
<?xml version="1.0"?>
<Object>
  <Header>
    <XCOMVers>V1.0</XCOMVers>
    <REPORT>XXXXX</REPORT>
    <CODE>002</CODE>
  </Header>
  <IssueCard>
    <Record>
	<L>CAR SYSTEM           -SSSSS  -</L>
      <L>                          CODE:      202</L>
      <L>---</L>
      <L>Message:</L>
      <L>:21:XXXXXXXX</L>
      <L>:103B:/1213-XX736472-567GH0</L>
      <L>---</L>
      <L>Confirm:</L>
	  <L>---</L>
      <L>Data Log:</L>
      <L>Created:                     Status-ID:        R-NO:       Details:</L>
      <L>2010-03-25-09.51.52.484529   CREATED           ICG-SSTS   Message log step 1</L>
      <L>                                                          4545454555</L>
      <L>2010-03-25-09.51.52.509229   SENDER    ICG-SSTS   Message log step 2</L>
      <L>2010-03-25-09.51.52.520070   EXIT-SYSTEM  ICG-SSTS   Message log step 3</L>
      <L>                                                          Message log step 5</L>
      <L>2010-03-25-09.51.53.157416   EXIT-OK-SYSTEM    ICG-SSTS   Message log step 6</L>
      <L>                                                          Message log step 7</L>
      <L>2010-03-25-09.51.53.171452   COMPLETED         ICG-SSTS   Message log step 8</L>
      <L>                                                          Message log step 9</L>
      <L>---</L>
    </Record>
  </IssueCard>
</Object>

To fetch the header column's value i'm using below code but having performance issue. As i'm getting 2gb file.
Code:
REPORT=`perl -nle 'print /(?<=REPORT>).*?(?=<\/REPORT>)/g' Inputfile | awk '(NR==3)'`

So to fetch 15 columns value like this and for thousands of records is a performance barrier here. Is there any other way to doing this task.

Other biggest challenge i'm facing is to fetch the value under section <Data log:>
i want output for CREATED status and for COMPLETED status only.
like:
Code:
CREATION_DATE				COMPLETION_DATE
2010-03-25-09.51.52.484529	2010-03-25-09.51.53.171452

Please guys help me.
# 2  
Old 06-19-2012
Based on the input given .. Try with this ..
Code:
$ nawk '/CREATED|COMPLETED/{split($1,a,">"); print a[2]}' infile
2010-03-25-09.51.52.484529
2010-03-25-09.51.53.171452
2010-03-25-09.51.52.484529
2010-03-25-09.51.53.171452

This User Gave Thanks to jayan_jay For This Post:
# 3  
Old 06-20-2012
how to get last status-id from these records?

Code:
<L>Created:                     Status-ID:        R-NO:       Details:</L>
      <L>2010-03-25-09.51.52.484529   CREATED           ICG-SSTS   Message log step 1</L>
      <L>                                                          4545454555</L>
      <L>2010-03-25-09.51.52.509229   SENDER    ICG-SSTS   Message log step 2</L>
      <L>2010-03-25-09.51.52.520070   EXIT-SYSTEM  ICG-SSTS   Message log step 3</L>
      <L>                                                          Message log step 5</L>
      <L>2010-03-25-09.51.53.157416   EXIT-OK-SYSTEM    ICG-SSTS   Message log step 6</L>
      <L>                                                          Message log step 7</L>
      <L>2010-03-25-09.51.53.171452   COMPLETED         ICG-SSTS   Message log step 8</L>
      <L>                                                          Message log step 9</L>

I want output as
Code:
COMPLETED

which is the last status-id.

pls help to get this.
# 4  
Old 06-20-2012
how to get last status-id from these records?

Looking for all lines that end with tag </L> & Considering the output to be always present in 3rd last line :

Code:
grep -n "\/L>" xmlfile | tail -3 | head -1 | awk '{print $3}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pull multiple XML tags from the same XML file in Shell.?

I'm searching for the names of a TV show in the XML file I've attached at the end of this post. What I'm trying to do now is pull out/list the data from each of the <SeriesName> tags throughout the document. Currently, I'm only able to get data the first instance of that XML field using the... (9 Replies)
Discussion started by: hungryd
9 Replies

2. Shell Programming and Scripting

Getting error while including values in xml tags using shell script

Hi All, Please find the code below where I want to add the variable value in between the XML tags. I am taking one string and my goal is to put them between the xml tags. Ex : in between <name> , <lname> Kindly suggest a correction because while executing this script I am getting and... (8 Replies)
Discussion started by: rajneesh4U
8 Replies

3. Shell Programming and Scripting

Parse XML For Values

Hi All, I want to parse XML to extract values of the tags to do further processing. The XML looks like <?xml version="1.0" encoding="ISO-8859-1"?> <allinput> <input A="2389906" B="install"> <C>111</C> <D>222</D> <E>333</E> <F></F> <G>444</G> <H></H> <I></I> <J></J> <K>C,D,E,G</K>... (6 Replies)
Discussion started by: rahulmittal87
6 Replies

4. Shell Programming and Scripting

Comparing delta values of one xml file in other xml file

Hi All, I have two xml files. One is having below input <NameValuePair> <name>Daemon</name> <value>tcp:7474</value> </NameValuePair> <NameValuePair> <name>Network</name> <value></value> </NameValuePair> ... (2 Replies)
Discussion started by: sharsour
2 Replies

5. Shell Programming and Scripting

How to add Xml tags to an existing xml using shell or awk?

Hi , I have a below xml: <ns:Body> <ns:result> <Date Month="June" Day="Monday:/> </ns:result> </ns:Body> i have a lookup abc.txtt text file with below details Month June July August Day Monday Tuesday Wednesday I need a output xml with below tags <ns:Body> <ns:result>... (2 Replies)
Discussion started by: Nevergivup
2 Replies

6. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

7. Shell Programming and Scripting

Shell Command to compare two xml lines while ignoring xml tags

I've got two different files and want to compare them. File 1 : HTML Code: <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record... (1 Reply)
Discussion started by: Shaishav Shah
1 Replies

8. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

9. Shell Programming and Scripting

Parsing Values from XML

Hi all, Can anyone help me out in parsing values from the xml in shell script below.. <DropDB> <DBName>RMDatabase</DBName> <UName>root</UName> <PWord>test</PWord> </DropDB> I need the values RMDatabase , root and test alone ... :wall: Thanks in advance :) ... (2 Replies)
Discussion started by: selvarajvs
2 Replies

10. Web Development

Replace xml values

Hallo all, I try to create a bash script but till now without any positiv results. The script should replace different variables in a text file with the right xml values Look at the following xml file: file.xml =================================== <?xml version="1.0"... (1 Reply)
Discussion started by: research3
1 Replies
Login or Register to Ask a Question