How to grep a text file which contains some binary data?

后端 未结 11 1694
遇见更好的自我
遇见更好的自我 2020-11-30 19:48

grep returns

Binary file test.log matches

For example

echo    \"line1 re \\x00\\r\\nline2\\r\\nline3 re\\r\\n\" > test.log  # in zsh         


        
11条回答
  •  感情败类
    2020-11-30 20:16

    Starting with Grep 2.21, binary files are treated differently:

    When searching binary data, grep now may treat non-text bytes as line terminators. This can boost performance significantly.

    So what happens now is that with binary data, all non-text bytes (including newlines) are treated as line terminators. If you want to change this behavior, you can:

    • use --text. This will ensure that only newlines are line terminators

    • use --null-data. This will ensure that only null bytes are line terminators

提交回复
热议问题