Shell Script to compare xml files and print output to a file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Shell Script to compare xml files and print output to a file
# 1  
Old 03-28-2011
Shell Script to compare xml files and print output to a file

All,
PLease can you help me with a shell script which can compare two xml files and print the difference to a output file.

I have attached one such file for you reference.
Code:
<Group>
        <Member ID=":Year_Quad:41501" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Jan 24, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Jan 24, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Jan 24, 2010"/>
        <Member ID=":Year_Quad:43061" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Feb 21, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Feb 21, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Feb 21, 2010"/>
        <Member ID=":Year_Quad:53700" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Mar 21, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Mar 21, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Mar 21, 2010"/>
        <Member ID=":Year_Quad:56518" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Apr 18, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Apr 18, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Apr 18, 2010"/>
        <Member ID=":Year_Quad:61671" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending May 16, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending May 16, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending May 16, 2010"/>
        <Member ID=":Year_Quad:65270" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Jun 13, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Jun 13, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Jun 13, 2010"/>
        <Member ID=":Year_Quad:72066" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Jul 11, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Jul 11, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Jul 11, 2010"/>
        <Member ID=":Year_Quad:74935" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Aug 08, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Aug 08, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Aug 08, 2010"/>
        <Member ID=":Qtr_Quad:79532" childCount="4" fullPath="PEPSICO Qtr-Quad-Wk : FOLDER.12 Weeks Ending Sep 05, 2010.4 Weeks Ending Sep 05, 2010" levelDisplayName="Qtr_Quad" levelName="Qtr_Quad" name="4 Weeks Ending Sep 05, 2010" qname="12 Weeks Ending Sep 05, 2010.4 Weeks Ending Sep 05, 2010"/>
        <Member ID=":Year_Quad:84091" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Oct 03, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Oct 03, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Oct 03, 2010"/>
        <Member ID=":Year_Quad:86333" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Oct 31, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Oct 31, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Oct 31, 2010"/>
        <Member ID=":Year_Quad:93502" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Nov 28, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Nov 28, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Nov 28, 2010"/>
        <Member ID=":Year_Quad:101615" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.52 Weeks Ending Dec 26, 2010.4 Weeks Ending Dec 26, 2010" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Dec 26, 2010" qname="52 Weeks Ending Dec 26, 2010.4 Weeks Ending Dec 26, 2010"/>
        <Member ID=":Year_Quad:105728" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.Building 52 Weeks Ending Dec 25, 2011.4 Weeks Ending Jan 23, 2011" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Jan 23, 2011" qname="Building 52 Weeks Ending Dec 25, 2011.4 Weeks Ending Jan 23, 2011"/>
        <Member ID=":Year_Quad:112734" childCount="4" fullPath="PEPSICO Year-Quad-Wk : FOLDER.Building 52 Weeks Ending Dec 25, 2011.4 Weeks Ending Feb 20, 2011" levelDisplayName="Year_Quad" levelName="Year_Quad" name="4 Weeks Ending Feb 20, 2011" qname="Building 52 Weeks Ending Dec 25, 2011.4 Weeks Ending Feb 20, 2011"/>
       </Group>
<CellValues>
      <Cell>
       <Value>10.319602657312</Value>
      </Cell>
      <Cell>
       <Value>11.707812842422</Value>
      </Cell>
      <Cell>
       <Value>9.6536930825463</Value>
      </Cell>
      <Cell>
       <Value>11.419761798981</Value>
      </Cell>
      <Cell>
       <Value>10.341018577406</Value>
      </Cell>
      <Cell>
       <Value>11.965773227183</Value>
      </Cell>
      <Cell>
       <Value>11.936577338803</Value>
      </Cell>
      <Cell>
       <Value>10.829760074249</Value>
      </Cell>
      <Cell>
       <Value>10.598210636264</Value>
      </Cell>
</Values>


In the second file the values within the tags <Value></Value> will change.

PLease advice.

Last edited by pludi; 03-28-2011 at 09:51 AM..
# 2  
Old 03-28-2011
this question seems similar to https://www.unix.com/unix-dummies-que...ted-files.html
Also I think you may be able to use diff?
# 3  
Old 03-28-2011
There are two excellent opensource tools which already do this: XMLdiff and diffxml.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare two files and print output

Hi All, i am trying to compare two files in Centos 6. F1: /tmp/d21 NAME="xvda" TYPE="disk" SIZE="40G" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="" NAME="xvda1" TYPE="part" SIZE="500M" OWNER="root" GROUP="disk" MODE="brw-rw----" MOUNTPOINT="/boot" NAME="xvda2" TYPE="part"... (2 Replies)
Discussion started by: balu1234
2 Replies

2. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

Compare columns of multiple files and print those unique string from File1 in an output file.

Hi, I have multiple files that each contain one column of strings: File1: 123abc 456def 789ghi File2: 123abc 456def 891jkl File3: 234mno 123abc 456def In total I have 25 of these type of file. (5 Replies)
Discussion started by: owwow14
5 Replies

5. Shell Programming and Scripting

Comparing 2 xml files and print the differences only in output

Hi....I'm having 2 xml files, one is having some special characters and another is a clean xml file does not have any special characters. Now I need one audit kind of file which will show me only from which line the special characters have been removed and the special characters. Can you please... (1 Reply)
Discussion started by: Krishanu Saha
1 Replies

6. Shell Programming and Scripting

compare two files and search keyword and print output

You have two files to compare by searching keyword from one file into another file File A 23 >pp_ANSWER 24 >aa hello 25 >jau head wear 66 >jss oops 872 >aqq olps ploww oww sss 722 >GG_KILLER ..... large files File B Beta done KILLER John Mayor calix meyers ... (5 Replies)
Discussion started by: cdfd123
5 Replies

7. Shell Programming and Scripting

awk to compare flat files and print output to another file

Hello, I am strugling from quite a some time to compare flat files with over 1 million records could anyone please help me. I want to compare two pipe delimited flat files, file1 with file2 and output the unmatched rows from file2 in file3 Sample File1: ... (9 Replies)
Discussion started by: suhaeb
9 Replies

8. Shell Programming and Scripting

compare columns from seven files and print the output

Hi guys, I need some help to come out with a solution . I have seven such files but I am showing only three for convenience. filea a5 20 a8 16 fileb a3 42 a7 14 filec a5 23 a3 07 The output file shoud contain the data in table form showing first field of... (7 Replies)
Discussion started by: smriti_shridhar
7 Replies

9. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies
Login or Register to Ask a Question