Unix/Linux Go Back    


Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

How join two xml files?

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-11-2016
Tapiocapioca Tapiocapioca is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 February 2017, 10:56 AM EST
Posts: 17
Thanks: 10
Thanked 0 Times in 0 Posts
How join two xml files?

I am totally new about the universe of scripting and I am using linux command under windows.
I need join two xml files in only one, the files have a specific structure

File one


Code:
<?xml version="1.0" encoding="UTF-8"?>
<tv generator-info-name="xxx" generator-info-url="www.xxx.com">
  <channel id="Rai Uno">
    <display-name lang="it">Rai Uno</display-name>
  </channel>
  <channel id="Rai Due">
    <display-name lang="it">Rai Due</display-name>
  </channel>
  <channel id="Rai Tre">
    <display-name lang="it">Rai Tre</display-name>
  </channel>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rai Uno">
    <title lang="it">Tg1</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rai Due">
    <title lang="it">Tg2</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rai Tre">
    <title lang="it">Tg3</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  </tv>

File two


Code:
<?xml version="1.0" encoding="UTF-8"?>
<tv generator-info-name="xxx" generator-info-url="www.xxx.com">
  <channel id="Rai Uno">
    <display-name lang="it">Rete 4</display-name>
  </channel>
  <channel id="Rai Due">
    <display-name lang="it">Canale 5</display-name>
  </channel>
  <channel id="Rai Tre">
    <display-name lang="it">Italia 1</display-name>
  </channel>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rete 4">
    <title lang="it">Tg4</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Canale 5">
    <title lang="it">Tg5</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Italia 1">
    <title lang="it">Tg6</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  </tv>

I need one file like


Code:
 <?xml version="1.0" encoding="UTF-8"?>
<tv generator-info-name="xxx" generator-info-url="www.xxx.com">
  <channel id="Rai Uno">
    <display-name lang="it">Rai Uno</display-name>
  </channel>
  <channel id="Rai Due">
    <display-name lang="it">Rai Due</display-name>
  </channel>
  <channel id="Rai Tre">
    <display-name lang="it">Rai Tre</display-name>
  </channel>
  <channel id="Rai Uno">
    <display-name lang="it">Rete 4</display-name>
  </channel>
  <channel id="Rai Due">
    <display-name lang="it">Canale 5</display-name>
  </channel>
  <channel id="Rai Tre">
    <display-name lang="it">Italia 1</display-name>
  </channel>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rai Uno">
    <title lang="it">Tg1</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rai Due">
    <title lang="it">Tg2</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rai Tre">
    <title lang="it">Tg3</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Rete 4">
    <title lang="it">Tg4</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Canale 5">
    <title lang="it">Tg5</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  <programme start="20160611004000 +0200" stop="20160611005500 +0200" channel="Italia 1">
    <title lang="it">Tg6</title>
    <sub-title>notiziario</sub-title>
    <desc lang="it">bla bla bla</desc>
  </programme>
  </tv>

I tried to do it with sed, but I can't. Can someone help me? Please don't suggest me scripting really advanced becuase I can only lunch command by command.

Thank you in advice to everybody!
Sponsored Links
    #2  
Old Unix and Linux 06-11-2016
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 March 2017, 3:46 PM EDT
Location: San Jose, CA, USA
Posts: 10,110
Thanks: 501
Thanked 3,500 Times in 2,980 Posts
I have never heard of a linux command on Windows.

Are the files you want to merge on Windows or are they on a Linux system that you are accessing while you are logged into a Windows system?

Are you running Linux-like commands on your Windows system provided as part of something like Cygwin or are you logging into a Linux system using something like rsh and running commands directly on a Linux system?
The Following User Says Thank You to Don Cragun For This Useful Post:
Tapiocapioca (06-11-2016)
Sponsored Links
    #3  
Old Unix and Linux 06-11-2016
Tapiocapioca Tapiocapioca is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 February 2017, 10:56 AM EST
Posts: 17
Thanks: 10
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Don Cragun View Post
I have never heard of a linux command on Windows.

Are the files you want to merge on Windows or are they on a Linux system that you are accessing while you are logged into a Windows system?

Are you running Linux-like commands on your Windows system provided as part of something like Cygwin or are you logging into a Linux system using something like rsh and running commands directly on a Linux system?
No I am not using Cygwin, I am using the project GnuWin Packages, is quite old but works in great way. I write the linux commands directly on the dos shell, but all commands are working really well. Before have the srtructure I posted I cleaned many parts of the files deleting blank lines and tags I don't need with sed. But about join I am not able Linux
    #4  
Old Unix and Linux 06-11-2016
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 March 2017, 3:46 PM EDT
Location: San Jose, CA, USA
Posts: 10,110
Thanks: 501
Thanked 3,500 Times in 2,980 Posts
Can you execute the command sh or bash or ksh to get an interactive Linux shell?

Can you put a Linux shell script into a file (for example script.sh and execute that script with one of the following three commands?:

Code:
sh script.sh
bash script.sh
ksh script.sh

Are the files you want to read really named one and two?

Do you want to merge file two into file one, or do you want to create a third file (three)?
Sponsored Links
    #5  
Old Unix and Linux 06-11-2016
Tapiocapioca Tapiocapioca is offline
Registered User
 
Join Date: Jun 2016
Last Activity: 22 February 2017, 10:56 AM EST
Posts: 17
Thanks: 10
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Don Cragun View Post
Can you execute the command sh or bash or ksh to get an interactive Linux shell?

Can you put a Linux shell script into a file (for example script.sh and execute that script with one of the following three commands?:

Code:
sh script.sh
bash script.sh
ksh script.sh

Are the files you want to read really named one and two?

Do you want to merge file two into file one, or do you want to create a third file (three)?
No I can't execute files .sh, I can only write the command one by one, I can only make one file .bat and process the commands like one list.

Just for example when I need delete che line start with the tag <url> I lunch the command


Code:
sed  -i "/<url/d" C:\epg-guide.xml

after I need copy the file and I use the dos command copy :P I know is really better if i can use directly linux, but the machine I am using is in Italy and I am in Indonesia, I can't reinstall the system Linux

The name of the files is like epg-guide_01.xml and epg-guide_02.xml and I need make one new file epg-guide_03.xml

Excuseme if I am not really clear about my request Linux

Last edited by RudiC; 06-11-2016 at 06:49 PM.. Reason: Added some code tags.
Sponsored Links
    #6  
Old Unix and Linux 06-11-2016
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 March 2017, 3:46 PM EDT
Location: San Jose, CA, USA
Posts: 10,110
Thanks: 501
Thanked 3,500 Times in 2,980 Posts
You are really tying our hands behind our backs here. You say you can execute Linux commands, but only if they are one-liners that don't use any shell language features like variable expansions and here-documents.

You say you have GNU tools. That must include sh (maybe sh.exe) and you must be able to execute that in a .bat file to execute a shell script with something like the following. Please create a .bat file containing:

Code:
sh.exe script.sh "argument 1" "argument 2"

And create a file named script.sh containing:

Code:
printf 'Arg1: "%s"\n' "$1"
printf 'Arg2: "%s"\n' "$2"

And then tell us what happens when you run that batch file.
Sponsored Links
    #7  
Old Unix and Linux 06-11-2016
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 23 March 2017, 1:32 AM EDT
Posts: 1,521
Thanks: 43
Thanked 568 Times in 534 Posts
Do you have Perl?


Code:
my $header = qq(<?xml version="1.0" encoding="UTF-8"?>);
my @tv_queue;
my %tv = ();
{
    local $/="</tv>\n";
    while(<>) {
        my ($generator) = /(<tv.*>)/;
        if (!$tv{$generator}){
           push @tv_queue, $generator;
        }
        push @{$tv{$generator}[0]}, /(\s{2}<channel.*channel>)/sm;
        push @{$tv{$generator}[1]}, /(\s{2}<programme.*programme>)/sm;
    }
}
print "$header\n";
for my $g (@tv_queue){
    print "$g\n";
    for my $i (@{$tv{$g}}) {
        print join("\n", @{$i}), "\n";
    }
    print "</tv>\n";
}

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Splitting a single xml file into multiple xml files Narendra921631 Shell Programming and Scripting 3 03-03-2016 02:50 PM
Extract strings from XML files and create a new XML milano.churchil Shell Programming and Scripting 12 06-22-2015 06:25 AM
How to use the the join command to join multiple files by a common column evelibertine UNIX for Dummies Questions & Answers 5 07-05-2012 04:15 PM
how to join two files using "Join" command with one common field in this problem? mindfreak UNIX for Dummies Questions & Answers 2 04-13-2012 05:55 AM
Join 2 files with multiple columns: awk/grep/join? InfoSeeker UNIX for Dummies Questions & Answers 3 12-01-2009 07:45 PM



All times are GMT -4. The time now is 04:23 PM.