Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #67671

Re: find and replace string in binary file

Date 2014-03-04 13:08 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: find and replace string in binary file
References <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.7708.1393938532.18130.python-list@python.org> (permalink)

Show all headers | View raw


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).

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

find and replace string in binary file loial <jldunn2000@gmail.com> - 2014-03-04 04:27 -0800
  Re: find and replace string in binary file MRAB <python@mrabarnett.plus.com> - 2014-03-04 13:08 +0000
  Re: find and replace string in binary file Peter Otten <__peter__@web.de> - 2014-03-04 14:18 +0100
  Re: find and replace string in binary file Chris Angelico <rosuav@gmail.com> - 2014-03-05 09:44 +1100
  Re: find and replace string in binary file emile <emile@fenx.com> - 2014-03-04 16:13 -0800
    Re: find and replace string in binary file loial <jldunn2000@gmail.com> - 2014-03-05 01:59 -0800
      Re: find and replace string in binary file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-05 12:42 +0000
      Re: find and replace string in binary file Emile van Sebille <emile@fenx.com> - 2014-03-05 09:46 -0800
  Re:find and replace string in binary file Dave Angel <davea@davea.name> - 2014-03-05 07:06 -0500

csiph-web