How to find string in binary file using only read(1) ?
For example I want to found position of string ‘abst’ in file ( without load to memory ) ?
It’s work but very primitive:
#!/usr/bin/python2
f = open("/tmp/rr", "rb")
f.seek(0)
cont = 1
while(cont):
a1 = f.read(1)
if a1 == 'a':
a2 = f.read(1)
if a2 == 'b':
a3 = f.read(1)
if a3 == 's':
a4 = f.read(1)
if a4 == 't':
found = True
cont = 0
You can find a substring by using the strings find-method.
The
read(1)-method is absolutely senseless. #see editEdit: more effiecient for the memory
I see, using
read(1)isn’t that senseless.