Monday, September 24, 2012

Splitting binary file in two

All answers to this question involved using unix. No surprise.

Early hunts for an answer to this question involved the "split" command. However, split seems to be geared for cutting files into evenly sized pieces only, and not a single arbitrarily placed cut.

That's okay, because "dd" is my new best buddy. It's loaded with arguments, all of which have a lovely archaic format, and can do any number of cuts anywhere. The version of this command that I will henceforth use until the grave is any variation of the following:

for first half:
dd bs=1st location after split count=1 if=infile of=outfile
for last half
dd bs=1st location after split skip=1 if=infile of=outfile

The main hints were found in this forum thread:

http://unix.stackexchange.com/questions/6852/best-way-to-remove-bytes-from-the-start-of-a-file

This other thread is nearly all above my head; neat shmott shtuff, but this where I first got a clue of the existence of dd. I wonder what xxd is?:

http://stackoverflow.com/questions/9451890/how-to-dump-part-of-binary-file