I've just hit the exact same problem (although it's only a multi-megabyte log file). As with a lot of problems, it just takes a couple of commands together.
cmp /path/to/file.log <(strings /path/to/file.log)
cmp
compares files and tells you where they differ (unlike diff, which tells you how they differ). strings
returns valid text strings from binary files. <(…)
lets you treat the output of a command as a file descriptor into another command.
Basically, you compare the log file with the text strings in the log file so that you find where they first differ.
For example, I get A and B differ: byte 1450315, line 6390
. Running tail -n +6390 /path/to/file.log | less
shows the log starting at the "bad" line, or you can pipe through | hexdump -C | less
to see the hex (piping through head -n 1
didn't work for me because the binary was \x00
characters, which only showed when there was a pager)
(Note: This may not work well with multi-gigabyte logs if the machine does not have sufficient memory - I don't know how memory efficient strings
and cmp
are)