Since two persons already voted to close this post, I'll try to make the question as clear as possible. A file on a physical device is represented as a binary sequence. That being said, what I need to do is to check the differences between the representations of two files at a such level (i.e. I need to compare the differences between multiple bytes on the same position across two different files), and to output such differences in a bash
script.
Example:
file1: 00000000 01010101 10101010 11001100 00110011
file2: 00000000 01010101 01010101 00110011 00110011
The script should output:
differences: Byte 3 (file 1: 01010101; file2 10101010), Byte 4 (file1: 11001100; file 2: 00110011)
Or something along these lines.
So the first thing I need to do in order to accomplish this is to be at least able to open a file at a certain position and to read one byte and to output/store such byte. I could write a C
program to do that, but is there a way to do this within bash
?
cmp(1)
? Otherwise I don't understand, what you want.00000000 01010101 10101010 ...
be the binary representation of a file; I need to extract some bytes in the position I want: for example I should be able to extract01010101
with something likevar=$(getbyte 2 file)
; but since I need to use this to compare and output the differences between two files, thecmp
solution below works perfectly for me