I have 2 Binary Files FileA
and FileC
Its is such that FileC = FileA + FileB
using the cat
utility
How do I subtract FileA
from FileC
to get FileB
?
PS: I am using Ubuntu Oneiric
I have 2 Binary Files FileA
and FileC
Its is such that FileC = FileA + FileB
using the cat
utility
How do I subtract FileA
from FileC
to get FileB
?
PS: I am using Ubuntu Oneiric
Assuling you have stat
on your plateform to get the size of FileA
, you could do something like:
dd if=./FileC of=./FileB bs=1 skip=$(stat -c %s ./FileA)
which should work on any type of file.
You need to know where to cut. For binary files, this generally means knowing the size of FileA
or FileB
.
You can find the size of FileA
with ls -l
. If you need to write a portable script, you can extract the size with ls -lgo FileA | awk '{print $3; exit}'
(or, for non-POSIX-compliant versions of ls
that don't have the -g
and -o
options, ls -l FileA | awk '{print $5; exit}'
). On non-embedded Linux, a simpler way to obtain the size is stat -c %s FileA
.
Once you have the size, you can use tail
to extract the second part of the file:
tail -c +$((sizeA + 1)) <FileC
If you want to break a file into equal chunks, use the split
command.