grep --byte-offset 不给我字节偏移量?

ane*_*yzm 4 grep

我跑

grep -b --byte-offset 'EXTH' Agent_of_Change.mobi
Run Code Online (Sandbox Code Playgroud)

但我只得到“二进制文件 Agent_of_Change.mobi 匹配”。我怎样才能得到字节偏移量?

dev*_*ull 5

grep默认情况下,只返回二进制文件的匹配项

您需要告诉grep将二进制文件视为文本。

grep -a -b 'EXTH' Agent_of_Change.mobi
Run Code Online (Sandbox Code Playgroud)

但是,grep警告您可能的后果:

          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.
Run Code Online (Sandbox Code Playgroud)