
私は走る
grep -b --byte-offset 'EXTH' Agent_of_Change.mobi
ただし、「バイナリファイルAgent_of_Change.mobi一致」のみが表示されます。バイトオフセットをどのように取得できますか?
答え1
grep
基本的にはマッチバイナリファイルの場合。
grep
バイナリをテキストとして扱うように指示する必要があります。
grep -a -b 'EXTH' Agent_of_Change.mobi
ただし、次の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.
答え2
-a
印刷できないように見えても、一致を強制的に印刷するように追加されました。
追加したら、行の-o
代わりに「EXTH」のみを印刷します。また、バイトオフセットを変更します。 「EXTH」を含む行の開始オフセットではなく、「EXTH」のオフセットを印刷します。ファイルが実際に行で構成されていない場合は、改善されました!
または、perl -n0777e 'print pos()-length($&),"\n" while /EXTH/g'
GNU grepの依存関係をより一般的な依存関係に置き換えます...