Sponsored Content
Top Forums Shell Programming and Scripting Extract and parse XML data (statistic value) to csv Post 302587951 by mirni on Friday 6th of January 2012 11:08:51 AM
Old 01-06-2012
Hmm... it works for me:
Code:
$ sed -n '/<measInfo measInfoId="25250000">/,/<\/measInfo>/  {/^<measValue / {s/.*Label=\([^"]*\).*/\1/^<measResults>\([0-9 ]*\).*/\1/ ;H; x; s/\n//; p  } }' stats.xml 
Site-O:MD0035-O-A-2, ID=591350 0 0 27300 100194 141378 2282 0 0 379 5849362 0 0 2497 0 
Site-O:MA0340-O-A-2, ID=565750 0 0 2099 11649 11091 28 0 0 74 249108 0 0 119 0 
Site-O:MD8001-O-A-3, ID=596460 0 0 0 549 0 0 0 0 0 1967 0 0 0 0 
Site-O:MA0056-O-A-2, ID=591550 0 0 0 1571 37 0 0 0 41 24453 0 0 0 0 
Site-O:MA0056-O-A-1, ID=591540 0 0 1349 4921 878 0 0 0 48 24651 0 0 0 0 
Site-O:MA0146-O-A-3, ID=571060 0 0 0 7018 106949 0 0 0 10 3928360 0 0 0 0 
Site-O:MA0120-O-B-3, ID=125610 0 0 8021 31504 1743 53 0 0 12 3939629 0 0 0 0 
Site-O:MA8105-O-A-3, ID=588960 0 0 0 2807 195 0 0 0 0 50977 0 0 0 0 
Site-O:MA0289-O-A-3, ID=576160 0 0 0 15665 10976 0 0 0 4 692551 0 0 831 0 
Site-O:MA0146-O-A-1, ID=571040 0 0 0 1884 237 0 0 0 1 13943 0 0 0 0

Where stats.xml is the copied'n'pasted stuff from your first post.
Does your file sampleCellbasedscript.txt contain exactly what you posted? Are there by any chance any whitespace characters at the beggining of the line with measValue tag?

Sed is infamous for its obscurity, but that is just on the first sight. Once you understand how it works, it is no mystery.

Try this:
Code:
sed -n '/<measInfo measInfoId="25250000">/,/<\/measInfo>/ p' inputFile

It should print the section between measInfo tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parse XML file into CSV with shell?

Hi, It's been a few years since college when I did stuff like this all the time. Can someone help me figure out how to best tackle this problem? I need to parse a file full of entries that look like this: <eq action="A" sectyType="0" symbol="PGR" exch="CA" curr="VEF" sess="NORM"... (7 Replies)
Discussion started by: Pcushing
7 Replies

2. 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

3. Shell Programming and Scripting

Extract and parse data between two strings

Hi , I have a billing CDR file which is separated by “!”. I need to extract and format data between the starting (“!”) and the end of the line (“1.2.1.8”). These two variables are permanent tags to show begin and end. ! TICKET NBR : 2 ! GSI : 101 ! 3100.2.112.1 24/03/2010 00:41:14 !... (3 Replies)
Discussion started by: jaygamini
3 Replies

4. Shell Programming and Scripting

Extract data from an XML file & write into a CSV file

Hi All, I am having an XML tag like: <detail sim_ser_no_1="898407109001000090" imsi_1="452070001000090"> <security>ADM1=????</security> <security>PIN1=????</security> <security>PIN2=????</security> ... (2 Replies)
Discussion started by: ss_ss
2 Replies

5. Shell Programming and Scripting

Extract multiple xml tag value into CSV format

Hi All, Need your assistance on another xml tag related issue. I have a xml file as below: <INVOICES> <INVOICE> <BILL> <BILL_NO>1234</BILL_NO> <BILL_DATE>01 JAN 2011</BILL_DATE> </BILL> <NAMEINFO> <NAME>ABC</NAME> </NAMEINFO> </INVOICE> <INVOICE> <BILL> <BILL_NO>5678</BILL_NO>... (12 Replies)
Discussion started by: angshuman
12 Replies

6. Shell Programming and Scripting

How to Parse the XML data along with the URL in Shell Script?

Hi, Can anybody help to solve this. I want to parse some xmldata along with the URL in the Shell. I'm calling the URL via the curl command Given below is my shell script file export... (7 Replies)
Discussion started by: Megala
7 Replies

7. Shell Programming and Scripting

Extract data from XML file and write in CSV file

Hi friend i have input as following XML file <?xml version="1.0"?> <Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.054.001.02"> <BkToCstmrDbtCdtNtfctn> <GrpHdr><MsgId>LBP-RDJ-TE000000-130042430010001001</MsgId><CreDtTm>2013-01-04T03:21:30</CreDtTm></GrpHdr>... (3 Replies)
Discussion started by: mohan sharma
3 Replies

8. Shell Programming and Scripting

BASH script to parse XML and generate CSV

Hi All, Hope all you are doing good! Need your help. I have an XML file which needs to be converted CSV file. I am not an expert of awk/sed so your help is highly appreciated!! XML file looks like this: <l:event dateTime="2013-03-13 07:15:54.713" layerName="OSB" processName="ABC"... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

9. Shell Programming and Scripting

Parse xml in shell script and extract records with specific condition

Hi I have xml file with multiple records and would like to extract records from xml with specific condition if specific tag is present extract entire row otherwise skip . <logentry revision="21510"> <author>mantest</author> <date>2015-02-27</date> <QC_ID>334566</QC_ID>... (12 Replies)
Discussion started by: madankumar.t@hp
12 Replies

10. Shell Programming and Scripting

Need a script to parse data and output to csv

I am not too savvy with arrays and am assuming that what I am looking for needs arrays. This is my requirement. So I have the raw data that gets updated to a log as shown below StudentInfo: FullInfo = { Address = Newark Age = 20 Name= John } StudentInfo:... (2 Replies)
Discussion started by: sidnow
2 Replies
XML-XREAD(1)							   User Commands						      XML-XREAD(1)

NAME
xml-xread - Parse XML documents with entity and URI resolution SYNOPSIS
xml-xread [options] xmlfile DESCRIPTION
xml-xread is a simple command line tool for parsing and validating XML documents. It is not an actual XML parser, it just wraps around a JAXP XMLReader, adding support for catalog-based entity and URI resolution. OPTIONS
-c catalogfile Load a particular catalog file. May be specified multiple times. -v Perform a validating parse. This is the default. -w Perform a well-formed parse, not a validating parse. -N Perform a namespace-aware parse. This is the default. -n Perform a namespace-ignorant parse. -d debuglevel Set the debug level (an integer). Warnings are shown if the debug level is set to greater than 2. -E maxerrors Set the maximum number of errors to display. The default is 10. FILES
/etc/java/resolver/CatalogManager.properties The central catalog manager configuration file used by xml-xread. SEE ALSO
xml-parse(1), xml-resolver(1), java(1), the OASIS entity resolution technical committee home page at <http://www.oasis-open.org/commit- tees/entity/>. AUTHOR
Norman Walsh <Norman.Walsh@Sun.COM> 1.1 July 2004 XML-XREAD(1)
All times are GMT -4. The time now is 01:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy