Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
GNU grep has the -a option to process as text, and I think maybe vim could suffice as a hex editor. –  new123456 Jun 26 '11 at 18:32

1 Answer 1

up vote 0 down vote accepted

This sounds like a job for perl:

perl -pe 's/start.*?end//g' < inputfile.bin > outputfile.bin
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.