Grep –byte-offset doesn’t give me the bytes offset

grep

I run

grep -b --byte-offset 'EXTH' Agent_of_Change.mobi

but I only get "Binary file Agent_of_Change.mobi matches".
How can I get the bytes offset instead?

Best Answer

grep would, by default, only returns matches for binary files.

You would need to tell grep to treat binary files as text.

grep -a -b 'EXTH' Agent_of_Change.mobi

However, grep warns you of the possible consequences:

          option.  If TYPE is text, grep processes a binary file as if  it
          were  text;  this is equivalent to the -a option.  Warning: grep
          --binary-files=text might output binary garbage, which can  have
          nasty  side  effects  if  the  output  is  a terminal and if the
          terminal driver interprets some of it as commands.