How join two xml files?

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions How join two xml files?
# 1  
Old 06-11-2016
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!
# 2  
Old 06-11-2016
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?
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 06-11-2016
Quote:
Originally Posted by Don Cragun
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 Smilie
# 4  
Old 06-11-2016
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)?
# 5  
Old 06-11-2016
Quote:
Originally Posted by Don Cragun
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 Smilie

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 Smilie

Last edited by RudiC; 06-11-2016 at 07:49 PM.. Reason: Added some code tags.
# 6  
Old 06-11-2016
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.
# 7  
Old 06-11-2016
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";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join, merge, fill NULL the void columns of multiples files like sql "LEFT JOIN" by using awk

Hello, This post is already here but want to do this with another way Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files file1.csv: 1|abc 1|def 2|ghi 2|jkl 3|mno 3|pqr file2.csv: 1|123|jojo 1|NULL|bibi... (2 Replies)
Discussion started by: yjacknewton
2 Replies

2. Shell Programming and Scripting

Help to join separate lines in a single one from xml file

Hi all, I need help to parse this xml file that has paragraphs broken in different lines and I would like to join in a single line. I hope you can understand my explanation. Thanks for any help/direction. The script could be in bash, awk, ruby, perl whatever please In the output I want:... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

3. Shell Programming and Scripting

Splitting a single xml file into multiple xml files

Hi, I'm having a xml file with multiple xml header. so i want to split the file into multiple files. Sample.xml consists multiple headers so how can we split these multiple headers into multiple files in unix. eg : <?xml version="1.0" encoding="UTF-8"?> <ml:individual... (3 Replies)
Discussion started by: Narendra921631
3 Replies

4. Shell Programming and Scripting

Splitting xml file into several xml files using perl

Hi Everyone, I'm new here and I was checking this old post: /shell-programming-and-scripting/180669-splitting-file-into-several-smaller-files-using-perl.html (cannot paste link because of lack of points) I need to do something like this but understand very little of perl. I also check... (4 Replies)
Discussion started by: mcosta
4 Replies

5. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

6. Shell Programming and Scripting

Join 2 files

I have file1.txt BGE179W1 BGE179W2 BGE179W3 BGE187W1 BGE187W2 BGE187W3 BGE194W1 BGE194W2 BGE194W3 BGE227W1 BGE227W2 BGE227W3 BGE288W1 BGE288W2 BGE288W3 BGE650W1 ---------- Post updated at 12:41 AM ---------- Previous update was at 12:39 AM ---------- (5 Replies)
Discussion started by: radius
5 Replies

7. Shell Programming and Scripting

Compare two xml files while ignoring some xml tags

I've got two different files and want to compare them. File 1 : <response ticketId="944" type="getQueryResults"><status>COMPLETE</status><description>Query results fetched successfully</description><recordSet totalCount="1" type="sms_records"><record id="38,557"><columns><column><name>orge... (2 Replies)
Discussion started by: Shaishav Shah
2 Replies

8. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

9. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

file1: Toronto:12439755:1076359:July 1, 1867:6 Quebec City:7560592:1542056:July 1, 1867:5 Halifax:938134:55284:July 1, 1867:4 Fredericton:751400:72908:July 1, 1867:3 Winnipeg:1170300:647797:July 15, 1870:7 Victoria:4168123:944735:July 20, 1871:10 Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies

10. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies
Login or Register to Ask a Question