For finding flash memory defects, I had to write this script which shows all 1K blocks which contain differences (not only the first one as cmp -b
does)
#!/bin/sh
f1=testinput.dat
f2=testoutput.dat
size=$(stat -c%s $f1)
i=0
while [ $i -lt $size ]; do
if ! r="`cmp -n 1024 -i $i -b $f1 $f2`"; then
printf "%8x: %s\n" $i "$r"
fi
i=$(expr $i + 1024)
done
Output:
2d400: testinput.dat testoutput.dat differ: byte 3, line 1 is 200 M-^@ 240 M-
2dc00: testinput.dat testoutput.dat differ: byte 8, line 1 is 327 M-W 127 W
4d000: testinput.dat testoutput.dat differ: byte 37, line 1 is 270 M-8 260 M-0
4d400: testinput.dat testoutput.dat differ: byte 19, line 1 is 46 & 44 $
Disclaimer: I hacked the script in 5 min. It doesn't support command line arguments nor does it support spaces in file names