LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-04-2014, 06:40 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
how to combine two xml files?


Hi,

i want to append File2 to the File1, could someone please help me to combine these two files?
File1:
Code:
<dataset>
<metadata>
<column name="OWNER" type="string"/>
<column name="AREA" type="string"/>
<column name="GROUP" type="string"/>
<column name="SERVICE" type="string"/>
<column name="KPI" type="string"/>
<column name="STATE" type="double"/>
<column name="LASTUPDATED" type="date"/>
<column name="DESCRIPTION" type="string"/>
<column name="SOURCE" type="string"/>
<column name="CITYPE" type="string"/>
</metadata>
<data>
<row>
 <OWNER>San Day</OWNER>
 <AREA>Helth SOLUTIONS</AREA>
 <GROUP>HEALTH</GROUP>
 <SERVICE>HEALTH CARE</SERVICE>
 <KPI>HTHTHT</KPI>
 <STATE>2.0</STATE>
 <LASTUPDATED>1393852190344</LASTUPDATED>
 <DESCRIPTION>10 #6,288,871.14</DESCRIPTION>
 <SOURCE>COC</SOURCE>
 <CITYPE>KPI</CITYPE>
</row>
<row>
 <OWNER>JAI</OWNER>
 <AREA>BUSINESS SOLUTIONS</AREA>
 <GROUP>TRANSACTION CLEARING SYSTEM</GROUP>
 <SERVICE>TRANSACTION CLEARING SYSTEM</SERVICE>
 <KPI>BLLBD201</KPI>
 <STATE>0.0</STATE>
 <LASTUPDATED>1393852210216</LASTUPDATED>
 <DESCRIPTION> Mon 03/03/14 13:10</DESCRIPTION>
 <SOURCE>COC</SOURCE>
 <CITYPE>KPI</CITYPE>
</row>
</data>
</dataset>
============================
File2:
Code:
<dataset>
<metadata>
<column name="OWNER" type="string"/>
<column name="AREA" type="string"/>
<column name="GROUP" type="string"/>
<column name="SERVICE" type="string"/>
<column name="KPI" type="string"/>
<column name="STATE" type="double"/>
<column name="LASTUPDATED" type="date"/>
<column name="DESCRIPTION" type="string"/>
<column name="SOURCE" type="string"/>
<column name="CITYPE" type="string"/>
</metadata>
<data>
<row>
 <OWNER>SSSSSS</OWNER>
 <AREA>SOLUTIONS</AREA>
 <GROUP>First</GROUP>
 <SERVICE>Last</SERVICE>
 <KPI>SLSLS</KPI>
 <STATE>0.0</STATE>
 <LASTUPDATED>1393492360782</LASTUPDATED>
 <DESCRIPTION>Job Completed Thu 27/02/14 09:12</DESCRIPTION>
 <SOURCE>COC</SOURCE>
 <CITYPE>KPI</CITYPE>
</row>
<row>
 <OWNER>ART</OWNER>
 <AREA>BUSINESS SOLUTIONS</AREA>
 <GROUP>IN</GROUP>
 <SERVICE>IN</SERVICE>
 <KPI>LILIL</KPI>
 <STATE>4.0</STATE>
 <LASTUPDATED>1393493391354</LASTUPDATED>
 <DESCRIPTION>GOOD</DESCRIPTION>
 <SOURCE>COC</SOURCE>
 <CITYPE>KPI</CITYPE>
</row>
</data>
</dataset>

Last edited by santosh0782; 03-04-2014 at 06:44 AM.
 
Old 03-04-2014, 07:34 AM   #2
s.verma
Member
 
Registered: Oct 2013
Distribution: Debian Sid, Gentoo, Arch, Debian
Posts: 169
Blog Entries: 4

Rep: Reputation: 24
Problem Restatement:
Let me first clarify what I have understood.

You have files with structure as follows:

<dataset>
<metadata>
.........somemetadata...
</metadata>
<data>
<row>
..........some1....
</row>
<row>
............some2......
</row>
.
.
.
</data>
</dataset>

Now you want to join these two data like

<dataset>
<metadata>
.........common metadata ...
</metadata>
<data>
<row>
..........some1 from file1....
</row>
<row>
............some2 from file1......
</row>
<row>
...........some1 from file2.....
</row>
<row>
...........some2 from file2....
</row>
.
.
</data>
</dataset>

Now if I am correct,

then put these commands as written in a file,

Code:
cat > file << EOF
`egrep -v '<\/data>|<\/dataset>' file1`
`sed -n "/<row>/,/<\/row>/p" file2`
`echo '</data>'`
`echo '</dataset>'`
EOF
let say abc
in same directory as your file1, and file2, then run

Code:
bash abc
It will create file which would have combined data of file1 & file2
 
1 members found this post helpful.
Old 03-05-2014, 05:46 AM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
This is really very good. Thanks a lot friend :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Combine files with offset AdamD Linux - Newbie 9 02-27-2013 04:44 AM
combine two files Syed Tarique Moin Programming 16 07-05-2010 12:30 PM
what to use to combine news: newsreader + RSS flux + XML format + evtl. webpages ? frenchn00b Linux - Software 0 12-08-2009 01:26 AM
combine shadow files packets Linux - Newbie 2 04-18-2008 06:14 AM
Best way to combine files? JockVSJock Programming 4 04-25-2004 08:38 PM


All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration