Sponsored Content
Top Forums Shell Programming and Scripting Convert XML to Data File in Shell Script Post 302420022 by ragha81 on Monday 10th of May 2010 11:10:22 AM
Old 05-10-2010
Convert XML to Data File in Shell Script

Hi All,

I will be getting a huge XML file with a lot of records in it. I need to convert it into multiple data files.

SAMPLE XML FILE

Code:
<ABSProductCatalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <ProductSalesHierachy>
- <Portfolios>
- <Portfolio productCode="P1">
  <Attribute name="CatalogProductName" value="Access" /> 
  <Attribute name="Status" value="Active" /> 
  </Portfolio>
- <Portfolio productCode="P2">
  <Attribute name="CatalogProductName" value="Data" /> 
  <Attribute name="Status" value="Active" /> 
  </Portfolio>
- <Portfolio productCode="P3">
  <Attribute name="CatalogProductName" value="Voice" /> 
  <Attribute name="Status" value="Active" /> 
  </Portfolio>
- <Portfolio productCode="P4">
  <Attribute name="CatalogProductName" value="Wireless" /> 
  <Attribute name="Status" value="Active" /> 
  </Portfolio>
  </Portfolios>
- <Families>
- <Family productCode="F1">
  <Attribute name="CatalogProductName" value="Internet Access Services" /> 
  <Attribute name="Status" value="Active" /> 
- <ParentHierarchy>
  <Item productCode="P1" modelType="Portfolio" /> 
  </ParentHierarchy>
  </Family>
- <Family productCode="F2">
  <Attribute name="CatalogProductName" value="Local Access Services" /> 
  <Attribute name="Status" value="Active" /> 
- <ParentHierarchy>
  <Item productCode="P2" modelType="Portfolio" /> 
  </ParentHierarchy>
  </Family>
  </Families>
- <SubFamilies>
- <SubFamily productCode="SF1">
  <Attribute name="CatalogProductName" value="Business Internet service" /> 
  <Attribute name="Status" value="Active" /> 
- <ParentHierarchy>
  <Item productCode="F1" modelType="Family" /> 
  </ParentHierarchy>
  </SubFamily>
  </SubFamilies>
- <ProductRefs>
- <ProductRef productCode="WSP1" modelType="Wireline Sales Product">
  <ActiveFlag>Y</ActiveFlag> 
- <ProductHierarchy>
  <SalesHierarchy family="F1" subFamily="SF1" portfolio="P1" primary="Y" /> 
  <SalesHierarchy family="F2" portfolio="P2" primary="N" /> 
  <FinancialHierarchy quotaBucket="Voice" strategicProdCategory="Local Voice" /> 
  </ProductHierarchy>
  </ProductRef>
- <ProductRef productCode="MSP2" modelType="Handset">
  <ActiveFlag>Y</ActiveFlag> 
- <ProductHierarchy>
  <SalesHierarchy portfolio="P4" primary="Y" /> 
  </ProductHierarchy>
  </ProductRef>
  </ProductRefs>
  </ProductSalesHierachy>
- <Offers>
- <Offer productCode="ABN">
  <OfferName>ABN</OfferName> 
  <OfferDescription>ABN Description</OfferDescription> 
- <Segments>
  <Segment>SCG</Segment> 
  <Segment>PCG</Segment> 
  </Segments>
  <OfferUpdateDate>2009-11-20</OfferUpdateDate> 
  <ActiveFlag>Y</ActiveFlag> 
  </Offer>
- <Offer productCode="OneNet">
  <OfferName>OneNet</OfferName> 
  <OfferDescription>OneNet Description</OfferDescription> 
- <Segments>
  <Segment>SCG</Segment> 
  <Segment>PCG</Segment> 
  <Segment>PCG2</Segment> 
  </Segments>
  <OfferUpdateDate>2009-11-20</OfferUpdateDate> 
  <ActiveFlag>Y</ActiveFlag> 
  </Offer>
  </Offers>
- <Products>
- <Product productCode="WSP1" modelType="Wireline Sales Product">
  <ProductName>AT&T High Speed Internet</ProductName> 
  <ProductDescription>High Speed Internet</ProductDescription> 
  <LegacyCoProdIndicator>SBC</LegacyCoProdIndicator> 
  <RevenueCBLCode>1234B</RevenueCBLCode> 
  <VolumeCBLCode>4567A</VolumeCBLCode> 
  <SAARTServiceIDCode>S1234</SAARTServiceIDCode> 
  <MarginPercentRequired>Y</MarginPercentRequired> 
  <PercentIntl>%234</PercentIntl> 
  <UOM>Each</UOM> 
  <PriceType>OneTime</PriceType> 
  <ProductStatus>Active</ProductStatus> 
  <Compensable>Y</Compensable> 
  <Jurisdiction>Everywhere</Jurisdiction> 
  <ActiveFlag>Y</ActiveFlag> 
- <Availabilities>
  <Availability>SE</Availability> 
  <Availability>E</Availability> 
  </Availabilities>
- <Segments>
  <Segment>SCG</Segment> 
  <Segment>PCG</Segment> 
  </Segments>
  <VDIndicator>Voice</VDIndicator> 
  <PSOCCode>PSOC 1</PSOCCode> 
  <USBilled>Y</USBilled> 
  <MOWBilled>N</MOWBilled> 
  <ProductStartDate>2009-11-20</ProductStartDate> 
  <ProductUpdateDate>2009-11-20</ProductUpdateDate> 
  <ProductEndDate>2010-11-20</ProductEndDate> 
- <AliasNames>
  <AliasName>AT&T HSI</AliasName> 
  <AliasName>AT&T Fast Internet</AliasName> 
  </AliasNames>
- <OfferTypes>
  <OfferType productCode="ABN" endDate="2009-11-20" /> 
  <OfferType productCode="OneNet" /> 
  </OfferTypes>
- <DynamicAttributes>
- <DynamicAttribute dataType="String" defaultValue="2.5 Mbps" name="Speed">
  <AttrValue>1.5 Mbps</AttrValue> 
  <AttrValue>2.5 Mbps</AttrValue> 
  <AttrValue>3.5 Mbps</AttrValue> 
  </DynamicAttribute>
- <DynamicAttribute dataType="String" name="TransportType">
  <AttrValue>T1</AttrValue> 
  </DynamicAttribute>
  </DynamicAttributes>
  </Product>
- <Product productCode="MSP2" modelType="Handset">
  <ProductName>Blackberry Bold</ProductName> 
  <ProductDescription>Blackberry Bold Phone</ProductDescription> 
  <LegacyCoProdIndicator /> 
  <RevenueCBLCode /> 
  <VolumeCBLCode /> 
  <SAARTServiceIDCode /> 
  <MarginPercentRequired /> 
  <PercentIntl /> 
  <UOM>Each</UOM> 
  <PriceType /> 
  <ProductStatus>Active</ProductStatus> 
  <Compensable /> 
  <Jurisdiction /> 
  <ActiveFlag>Y</ActiveFlag> 
- <Availabilities>
  <Availability /> 
  </Availabilities>
- <Segments>
  <Segment>SCG</Segment> 
  <Segment>PCG</Segment> 
  </Segments>
  <VDIndicator>Voice</VDIndicator> 
  <PSOCCode /> 
  <USBilled /> 
  <MOWBilled /> 
  <ProductStartDate>2009-11-20</ProductStartDate> 
  <ProductUpdateDate>2009-11-20</ProductUpdateDate> 
- <AliasNames>
  <AliasName /> 
  </AliasNames>
- <OfferTypes>
  <OfferType productCode="ABN" /> 
  </OfferTypes>
- <DynamicAttributes>
- <DynamicAttribute dataType="String" name="StlmntContractType">
  <AttrValue /> 
  </DynamicAttribute>
- <DynamicAttribute dataType="String" name="BMG 2 year price">
  <AttrValue>20</AttrValue> 
  </DynamicAttribute>
- <DynamicAttribute dataType="String" name="MSRP">
  <AttrValue>40</AttrValue> 
  </DynamicAttribute>
- <DynamicAttribute dataType="String" name="BMGAvailableType">
  <AttrValue /> 
  </DynamicAttribute>
- <DynamicAttribute dataType="String" name="ProductId">
  <AttrValue>123456</AttrValue> 
  </DynamicAttribute>
- <DynamicAttribute dataType="String" name="modelSource">
  <AttrValue>product</AttrValue> 
  </DynamicAttribute>
  </DynamicAttributes>
  </Product>
  </Products>
  <CatalogChanged>Y</CatalogChanged> 
  </ABSProductCatalog>

I need the above XML file broken down to multiple data files. For eg) Portfolio tag elements should go into Portfolio.txt The text file should be as below

P1|Access|Active

Similarly Family Tag elements should go into Family.txt, same with Sub Family and Products as well.

Can you suggest a way to achieve my scenario. I dont have much experience with shell scripting so excuse if my question is naive.

Thanks,
Raghav
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Plz Help To convert xml file to text file using bourn shell scripts

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> <country_code>AK></country_code>... (0 Replies)
Discussion started by: ram2s2001
0 Replies

2. Shell Programming and Scripting

extract data from xml- shell script using awk

Hi, This is the xml file that i have. - <front-servlet platform="WAS4.0" request-retriever="SiteMinder-aware" configuration-rescan-interval="60000"> <concurrency-throttle maximum-concurrency="50" redirect-page="/jsp/defaulterror.jsp" /> - <loggers> <instrumentation... (5 Replies)
Discussion started by: nishana
5 Replies

3. Shell Programming and Scripting

Sample Unix script file to convert .xml to .csv

Dear all, Can you send me a script file the changes .xml to .csv file. Thanks, Srinivasa (4 Replies)
Discussion started by: srinivasaphani
4 Replies

4. Shell Programming and Scripting

Help with shell script to extract data from XML file

Hello Scripting Gurus, I need help with extracting data from the XML file using shell script. The data is in a large XML and I need to extract the id values of all completedworkflows. Here is a sample of it. Input and output data is also in the attached text files. <wfregistry>... (5 Replies)
Discussion started by: yajaykumar
5 Replies

5. Shell Programming and Scripting

How to remove xml namespace from xml file using shell script?

I have an xml file: <AutoData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Table1> <Data1 10 </Data1> <Data2 20 </Data2> <Data3 40 </Data3> <Table1> </AutoData> and I have to remove the portion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" only. I tried using sed... (10 Replies)
Discussion started by: Gary1978
10 Replies

6. Shell Programming and Scripting

convert one form of xml data to other

I would like to convert one form of xml tag data to another <DescriptionList> <DescriptionExt language="en" shortDesc="ITALIAN SAUSAGE SUB" longDesc="" sizeDesc="" smallImage="Pictures\sub-italian-sausage.png" largeImage="" forceImageUpdate="yes" /> ... (1 Reply)
Discussion started by: saisus
1 Replies

7. UNIX for Advanced & Expert Users

Convert column data to row data using shell script

Hi, I want to convert a 3-column data to 3-row data using shell script. Any suggestion in this regard is highly appreciated. Thanks. (4 Replies)
Discussion started by: sktkpl
4 Replies

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

9. Shell Programming and Scripting

Convert XML to CSV using awk or shell script

Hello, I am working on a part of code where I need a awk or shell script to convert the given XML file to CSV or TXT file. There are multiple xml files and of different structure, so a single script is required for converting data. I did find a lot of solutions in the forum but... (16 Replies)
Discussion started by: Rashmitha
16 Replies

10. Shell Programming and Scripting

Need get data from XML file through shell script..

hi all, here is the sample log file and these errors are repeated in log file.. i need all the repeated time stamp ,severity and message tags needs to print in output file.. through shell script <log-message> <timestamp>2019-03-13T04:52:49.648-05:00</timestamp> <severity>ERROR</severity>... (17 Replies)
Discussion started by: ravi
17 Replies
All times are GMT -4. The time now is 03:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy