Showing posts with label remove bytes. Show all posts
Showing posts with label remove bytes. Show all posts

Friday, May 20, 2011

Remove First N bytes From a (Binary) File

Situation:
You have a (binary) file, and you need to remove the first n bytes of data in it.

Solution:
Use dd. Read more about it, here.

Here is how to do it:
$ dd if=input_file ibs=1 skip=N of=output_file

N is the number of bytes to be removed.

example:
$ dd if=input_file.dat ibs=1 skip=3 obs=10M of=output_file.dat


Now, what if you need to remove the first N bytes and the last M bytes from a file?
$ dd if=input_file.dat ibs=1 skip=N count=X of=output_file.dat

To calculate X:
X = acutal_file_size_in_bytes - N - M


I recommend you to read through the man pages, and play around with ibs, obs, bs, count values and other parameters that might be useful.