Command line solution for removing parts from a binary file?

Posted by zsero on Super User See other posts from Super User or by zsero
Published on 2011-06-26T16:15:55Z Indexed on 2011/06/26 16:23 UTC
Read the original article Hit count: 327

Filed under:
|
|
|
|

I have a binary file and I would like to remove parts from. By removing I mean deleting those parts and thus making the file's size smaller.

The parts would be between two ASCII strings. So, for example the file would look like this

........ start ABCD end ..... start EFGH end ..... start IJKL end ...........

So in this file, I would like to search for strings "start" and "end" and remove the parts between them.

The way I think I can do it is to

  1. lookup all the locations for "start" and "end"
  2. calculate ranges from that
  3. delete those parts

Now I am using some GUI based Hex editor and I use the "Search All", "Select Range" and "Delete" commands, but I am sure it would be possible to solve it using some powerful command line hex/text editors.

Do you know any solution for this problem which doesn't require using a GUI for looking up, copy & paste on clipboard, select range and delete commands but is just a few lines of command line?

I am interested ini both Linux shell scripts or using some command line hex editors under Windows, or even Python scrips are welcome.

Do you think it is possible to solve this problem just by a simple Regex replace? Are there any regex replace util which handles binary files well?

© Super User or respective owner

Related posts about Windows

Related posts about linux