compare 2 tar files using shell scripts

May 20, 2010 at 07:34:40
Specs: Windows XP
I need to come up with a script that compares 2 .tar files. We want to be able to run it on any tar file to compare them to previous version. It needs to be a shell script. Any ideas?

See More: compare 2 tar files using shell scripts

Report •

#1
May 20, 2010 at 09:42:17
Your requirements are too general. First, what shell are you using - bourne, korn, bash, etc?

Next, take a look at the cmp, compare two files, command. The command returns no output if the files are the same else the location where the files are different.


Report •

#2
May 20, 2010 at 10:01:23
We are using korn shell. we want to be able to see which files actually differ in the 2 tar files. Have it write it out to a txt file or something that shows for example in TAR1 these files are different than what is in TAR2, or these are in TAR2 but not in TAR1. Basically only the differences.

Report •

#3
May 20, 2010 at 13:02:29
I don't have time now to do any coding but here is place to start. Compare the table of contents of the 2 tar files. Here is the psuedo code

1) Get the table of contents of TAR2 and sort by the last field which is the file name- probably field 8 and save it to a file:

tar tvf TAR2 |sort -k 8,8 > /tmp/contentsTAR2.txt

2) Get table of contents of TAR1

tar tvf TAR1|sort -k 8,8 > /tmp/contentsTAR1.txt

3) Use the Unix diff command to get the differences between the 2 contents:

diff /tmp/contentsTAR2.txt /tmp/contentsTAR1.txt

You might have to tweak the algorithm above if the file sizes or creation dates cause you a problem.


Report •
Related Solutions


Ask Question