Just a one-shot, throwaway script I quickly concocted up yesterday, which I... don't feel like throwing away altogether: perhaps it will be instructive for others, although I warn in advance that for generic use it would require quite some massaging.
The problem: two big files (of the same actual size) which would definitely seem to be the same file, but indeed are not, as a checksum on each shows. I want to show the actual differences:
#!/usr/bin/perl use strict; use warnings; $|++; die "Usage: $0 file1 file2\n" unless @ARGV==2; my ($f1, $f2) = map { open my $fh, '<:raw', $_ or die "Can't open `$_': $!\n"; $fh } @ARGV; $/ = \0x100_000; while (my $s1=<$f1>) { defined +(my $s2=<$f2>) or last; printf "Block %04d: no differences\r", $. and next if $s1 eq $s2; my @l = map length, ($s1 ^ $s2) =~ /^(\0*)(.+?)(\0*)\z/; printf "\nBlock %04d: A=[0 x %d], B=[* x %d], C=[0 x %d]\n", $., @ +l; print "\tB=[@{[ unpack '(H2)*' => substr $_, $l[0], $l[1] ]}]\n" for $s1, $s2; } __END__
Funny detail, not only did the two files ended up differing by one single byte, but more precisely, by one single bit:
C:\temp>perl compare.pl foo bar Block 0727: no differences Block 0728: A=[0 x 759818], B=[* x 1], C=[0 x 288757] B=[e7] B=[ef] Block 0973: no differences
In reply to Finding differences in binary files by blazar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |