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

<?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

<?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

 <?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!

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?

1 Like

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 :frowning:

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?:

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

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

after I need copy the file and I use the dos command copy :stuck_out_tongue: 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 :frowning:

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 :smiley:

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:

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

And create a file named script.sh containing:

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

And then tell us what happens when you run that batch file.

Do you have Perl?

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";
}

I tried to find what you told me, but I can't find it. Here there is the list of the possible command hxxp://gnuwin32.sourceforge.net/packages.html I think what you told me is no available :frowning:

---------- Post updated at 04:20 PM ---------- Previous update was at 04:18 PM ----------

I have not but i think is avalaible, I try to find and install it.

There are binaries of Perl for windows as well.

I found and downloaded this hxxp://www.activestate.com/activeperl/downloads , but I am totally beginner about, what the way to use your script? Where can I input my files? Excuseme if I am asking really simple questions for you totally clear.

Moderator comments were removed during original forum migration.

Tell us a bit more about that Italy - Indonesia setup. Are both machines Windows? How do you connect/login? Is there an option to copy those files elsewhere?

I use remote desktop to connect to one machine with windows 7, is a real machine not virtual. I connect mysel from indonenesia to italy, but I think this is not really important :smiley: I tried to make some scripts with dos but the xml files I need edit are big like 100 mb and windows become crazy trying to modify big files, so I tried the solution of GnuWin32 Packages and works fine. But about join files with linux command I have not idea :frowning:

Save the snippet I posted as merge_xml.pl
Run at the command prompt as perl merge_xml.pl file1.xml file2.xml file3.xml > big.xml

This suggested code will accommodate as many files as you want to merge. It uses the following entries as unique ID

<tv generator-info-name="xxx" generator-info-url="www.xxx.com">