I need to find a string that matches a particular pattern in a very large log file (several GB). The problem is that I can only look at 512 bytes of the file at a time. As I compare the string 512 bytes at a time, the pattern isn't always found because it may overlap two different chunks. for example, if the pattern is "potato", the first part of the word may only exist at the end of one chunk, while the rest only exists on the beginning of the second chunk. 

Ideally, I'd like to substitute the pattern for a regex and only print the string that the pattern matched. I'd love to see how others would approach a problem like this. Any help would be greatly appreciated. 

```
import sys
import re

file = open(sys.argv[1], "rb")
pattern = re.compile('potato')

try:
    chunk= file.read(512)
    while byte != "":
        if pattern.search(chunk):
            print chunk
            # TODO: Print only the part that matched pattern
        chunk = file.read(100)
finally:
    file.close()

```