find and replace string in binary file

MRAB python at mrabarnett.plus.com
Tue Mar 4 08:08:50 EST 2014


On 2014-03-04 12:27, loial wrote:
> How do I read a binary file, find/identify a character string and
> replace it with another character string and write out to another
> file?
>
> Its the finding of the string in a binary file that I am not clear
> on.
>
> Any help appreciated
>
Read it in chunks and search each chunk (the chunks should be at least
as long as the search string).

You should note that the string you're looking for could be split
across 2 chunks, so when writing the code make sure that you include
some overlap between adjacent chunks (it's best if the overlap is at
least N-1 characters, where N is the length of the search string).



More information about the Python-list mailing list