Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] binary search of binary data



>>>>> "Edward" == Edward Wright <edw@example.com> writes:

    Edward> Feels like there should be a simple answer to this, but it
    Edward> eludes me.

It depends on what you want to do with the bytes, and how big the file
is.  Here's my guess

$ python
>>> infile = open (FILE, "r")
>>> s = infile.readlines()
>>> r = compile ("\xec\xa5\xc1\x01")
>>> m = r.search (s, 0)
>>> while m:
>>>  print "match at %d\n" % m.start()
>>>  m = r.search (s, m.end())
>>> 
>>> ^D
$

    Edward> which works sometimes - depending on the hex values, I
    Edward> suppose.

Don't guess at why.  Tell us exactly how it fails, preferably by
capturing a session and attaching it.




-- 
Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links