微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何通过看起来像文本的二进制文件?

我有二进制文件,应该是文本(它们是导出的日志),但我不能用更少的打开它(它看起来很难看 – 它看起来像一个二进制文件).我发现我可以用vi打开它,我可以捕捉它(你会看到实际的日志),但我真正喜欢的是通过它们(不必用vi打开每一个后执行)搜索).有没有办法让我这样做?

解决方法

您仍然可以使用grep来搜索文件 – 它并不关心输入文件是否真的是文本.来自’man grep’:
-a,--text
          Process a binary file as if it were text; this is equivalent to the --binary-files=text option.

   --binary-files=TYPE
          If  the  first few bytes of a file indicate that the file contains binary data,assume that the file is
          of type TYPE.  By default,TYPE is binary,and grep normally outputs either a one-line  message  saying
          that a binary file matches,or no message if there is no match.  If TYPE is without-match,grep assumes
          that a binary file does not match; this is equivalent  to  the  -I  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.

请在第二段末尾标注谨慎的字样.您可能希望将结果从grep重定向到新文件,并使用vi / less进行检查.

原文地址:https://www.jb51.cc/html/230064.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐