Parsing custom data into xml in Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing custom data into xml in Shell
# 1  
Old 02-13-2016
Parsing custom data into xml in Shell

Hi ,
I have data as below in a text file

Code:
{
'AAA' => {
       'A1' => 'a1 comment',
       'A2' => 'a2 comment'   
    },
'BBB' => {
      'B1' => 'b1 comment'
    },
'CCC' => {
      'C1' => 'c1 comment',
       'C2' => 'c2 comment',
       'C3' => 'c3 comment'
       'C4' => 'c4 cooment
    },
'DDD' => {
      'D1' => 'd1 comment'
    }
}

I want to parse this into a new XML file, so the output should look something like below,

Code:
<struct>
	<Table tName="AAA">
		<column name="A1">
			<columnComment>a1 comment</columnComment>
		</column>
		<column colName="A2">
			<columnComment>a2 comment</columnComment>
		</column>
	</Table>
	
	<Table tName="BBB">
		<column colName="B1">
			<columnComment>b1 comment</columnComment>
		</column>
	</Table>

</struct>

the command should be efficient and fast. Smilie

is it feasible to do this?

Last edited by vivek d r; 02-13-2016 at 02:18 AM.. Reason: wrong names
# 2  
Old 02-13-2016
This looks more like json to xml conversion. You have free tools online to do this. Please search once.
# 3  
Old 02-13-2016
If you have huge data and need lot of this kind of processing, thenlook Postgresql ex. newest 9.5.
It has builtin really fast JSON and XML input parser using "COPY" and very fast output from JSONtoXML and XMLtoJSON. PG include datatypes JSON, JSONB, XML, ...

PG is SQL DB, but it's also one the fastest noSQL environment to handle JSON, CSV, XML, ... files.

Small json set I use jq to convert/parse but bigger data set I parse using PG command psql.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing XML (and insert data) then output data (bash / Solaris)

Hi folks I have a script I wrote that basically parses a bunch of config and xml files works out were to add in the new content then spits out the data into a new file. It all works - apart from the xml and config file format in the new file with XML files the original XML (that ends up in... (2 Replies)
Discussion started by: dfinch
2 Replies

2. Shell Programming and Scripting

Help - Parsing data in XML in Linux

Hi, I have an XML file in Linux and it contains a long string of characters. The last part of the file is like ....... ....... ....... CAD</MarketDescription></InvestorTransaction></AdvisorAccount></DivisionAdvisor></Division>... (3 Replies)
Discussion started by: naveed
3 Replies

3. Shell Programming and Scripting

XML parsing using shell script

I have a xml file like this <bul:collectionStrategy name="strategy1"> <bul:collectionTemplateGroup name="15min group"/> <bul:collectionTemplateGroup name="hourly group"/> </bul:collectionStrategy> <bul:CollectionTemplateGroup name="hourly group" > ... (2 Replies)
Discussion started by: LavanyaP
2 Replies

4. Shell Programming and Scripting

XML parsing in a shell script.

Below is a XML I have... <?xml version="1.0" encoding="UTF-8" ?> <component xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:XXXXX-www-Install-Manifest manifest.xsd" xmlns="urn:qqqqq-Install-Manifest" name="OM" ... (1 Reply)
Discussion started by: dashok.83
1 Replies

5. Shell Programming and Scripting

parsing data from xml file is failing can't open variable

Created a korn shell script, everything is is working except this section, the variable $SYSINFO is being set, but the NASIP & NASDEV are failing, it appears to be treating the config.xml file config directory and xml as the file. Need a second set of eyes to tell me where I am messing up. #... (3 Replies)
Discussion started by: juanb25
3 Replies

6. Shell Programming and Scripting

Parsing XML using Shell Script

Hello, I'm a starting shell scripter and no Perl knowledge. I've trying to do this for a while: I want to parse an XML file and get certain data out of it and write that data into a CSV file, all this using Shell Scripting (in Bash). Or Perl without any XML Parser/Interpreter (if possible). ... (1 Reply)
Discussion started by: Kage Musha
1 Replies

7. Shell Programming and Scripting

Parsing posted XML data from a remote server?

Hi Is it possible to parse a posted xml data from a remote server in unix shell script. if so how to do that? and i need to give this script path in the push url (in remote server) . how to do this? I have tried this in asp but could not succeed....so am trying in shell scripting...the thread... (1 Reply)
Discussion started by: aemunathan
1 Replies

8. Shell Programming and Scripting

XML parsing through shell scritps

Hi, Am new to scripting. :) Am trying to figure out whether can i use bash scripting to parse an xml file. Parsing is not just pulling out information according to the pattern but its more of a generic parsing. I should identify the xml hierarchy and pull out information accordingly. It's not a... (2 Replies)
Discussion started by: karthikvela
2 Replies

9. Shell Programming and Scripting

Parsing and getting data from XML file using ksh script

Hi All, I have a xml file for example as described below <xml> <address> <street><street> <address/> <isbn>426728783932020308393930303</isbn> <book> <name> </name> </book> . . . </xml> My problem is to get the isbn number from the above described file using ksh script. Could... (6 Replies)
Discussion started by: vinna
6 Replies

10. UNIX for Dummies Questions & Answers

Parsing XML dynamic data via awk?

I am trying to use a line of output in an XML file as input in another new XML file for processing purposes via a shell script. Since I am a newbie though, I'm not sure how to do this since the data is different everytime. I am using this technique with static data right now: echo -n "Running... (5 Replies)
Discussion started by: corwin43
5 Replies
Login or Register to Ask a Question