3 ms·
So, what does trigger grep to regard a file as binary/non-text? For me, it seems these are not only NUL characters. And I also think that this would not be a d
by seppel 6y ago
So, what does trigger grep to regard a file as binary/non-text? For me, it seems these are not only NUL characters.
And I also think that this would not be a discussion if it was just about NUL. There is something else that grep does not like (escape characters? Invalid utf8? Wrong codepage? I don't know), but this makes the binary detection annoying.
- jwilk 6y agoI haven't looked at the GNU grep source, but yes, invalid UTF-8 is one of the reasons for treating file as binary: $ printf 'a\222b' | LC_ALL=en_US.UTF-8 grep a Binary file (standard input) matches This is POSIX-compliant, because "character" is defined as: > A sequence of one or more bytes representing a single graphic symbol or control code. https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_87 https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1...