Get line from file at specified byte offset

parsing, perl, python, unix

Solution

with open(filename, 'r') as f:    
    for offset in offsets:
        f.seek(offset)
        print(f.readline())

References:

- with statement

- open

- seek

- readline

Problem

I have a file with a bunch of lines. I have a list of the bytes offsets corresponding with the start of each line. I want each line that corresponds with the byte offset. Is there a way to do this in unix, perl or python? I have to do this at a much larger scale than described. File: ``` abcd bcde cdef ``` Byte Offsets: ``` 0 10 ``` Desired Output: ``` abcd cdef ```

Original source