Python - Help needed with parsing file. Is there a way to ignore EOF chars?
Question: I have a binary file that I am trying to extract strings from and I am having
quite the time doing so. :(

My current strategy is to read in the file using Python (using one of the
following functions: read(), readline(), or readlines()). Next, I parse
through the line (char by char) and look for the special character 'ô', which
in **most cases** directly follows the strings I want! Lastly, I parse
backwards from the special char recording all chars that I have identified as
being "valid."

At the end of the day, I want the front time stamp and the next 3 strings
within the line.

Results:

In the input example line #1 the "read" functions won't read through the
entire line (shown in the output image). I believe this is because the
function is interpreting the binary as an EOF char and then it stops reading
on.

In line #2 of the example, there are times in which the "special char" shows
up, however it is not after a string I want to extract. :(

Is there a better way to parse this data? If not, is there way to solve issue
seen in example line #1?

Examples of input data and the resulting output data when I just print the
lines as read. As you can see, it does not read through the entire line when
using `readlines()` [![Examples of input data and the resulting output data
when I just print the lines as read. As you can see, it does not read through
the entire line when using
readlines\(\)](http://i.stack.imgur.com/hTb11.png)](http://i.stack.imgur.com/hTb11.png)

My string extraction algorithm, which is not very robust. [![My string
extraction algorithm, which is not very
robust.](http://i.stack.imgur.com/nGLLf.png)](http://i.stack.imgur.com/nGLLf.png)

FYI, efficiency is not necessarily import.


Answer: Why use Python. Use strings and pipe it through head, eg

    
    
        strings /bin/ls | head -3
    

and see what you get. You can get a strings for Windows too.

