LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-19-2011, 05:39 AM   #1
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
binary diffing pairs of files


Hi,

I have a directory which contains in it multiple files (backups of virtual machines). They are named (for example):

webserver-19012011.xva
webserver-12012011.xva
webserver-05012011.xva
dbserver-19012011.xva
dbserver-12012011.xva
dbserver-05012011.xva

What I need to do is commit a diff (the files are in excess of 8GB) of the two latest files in each set (webserver diff and db server diff) and if they are identical delete one of them (not bothered which). The modification dates match the last characters, so ls -t is an option.

I've been working on this logic, however given my example it would only check the two webserver VM's:

Code:
diff --brief `ls -t /VM_container/ | tail -2`
I'm struggling with how to pair them up for the diff more than anything else :S. I think I can probably handle the rm bit, however it maybe easier to have a diff of two variables and then delete one of them.

Thanks, sorry if this is too verbose!
 
Old 01-19-2011, 06:19 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The diff command is designed for line oriented text files. Don't expect it to be able to handle binary files. To compare two binary files use `cmp'. It will tell you the offset where the files differ or they if are the same.

cmp file1 file2 && rm file1
 
1 members found this post helpful.
Old 01-19-2011, 06:30 AM   #3
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by jschiwal View Post
The diff command is designed for line oriented text files. Don't expect it to be able to handle binary files. To compare two binary files use `cmp'. It will tell you the offset where the files differ or they if are the same.

cmp file1 file2 && rm file1
Wow, thanks for that! I didn't even know I was looking through the diff man page and remember reading the word binary somewhere so assumed it would function as expected.
 
Old 01-19-2011, 07:21 AM   #4
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Original Poster
Rep: Reputation: 31
Evidently I've not tested this enough, diff and cmp both say the files differ. cmp says they differ on the first line; this is just a long string of settings used when commiting an import and isn't relevant to the actual data...

Just tried this with -l, thousands of differences; joy oh joy, new diff method needed I suspect, or perhaps an entirely new idea.

Thanks for your help guys

Last edited by genderbender; 01-19-2011 at 07:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to see the contain of binary files dhirendrs Programming 5 08-04-2010 03:21 AM
binary files earlysame55 Linux - Newbie 5 09-14-2009 03:11 PM
binary files nesta Programming 2 01-21-2007 08:42 PM
Using binary files KDE4me Linux - Newbie 1 04-24-2003 08:00 AM
Binary Files guywithredhat Linux - General 7 03-18-2003 06:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration