Hi,
Bored Videos <[email protected]> writes:
> My .histfile (something used by zsh) contains a binary character in
> one of its lines. But if I grep ab .histfile I get several lines
> showing matches, but after that it says grep: .histfile: binary file
> matches.
>
> Is this intended behavior?
Copying a section from the manual [1]:
By default, type is ‘binary’, and grep suppresses output after null
input binary data is discovered, and suppresses output lines that
contain improperly encoded data. When some output is suppressed,
grep follows any output with a message to standard error saying that
a binary file matches.
So, your matches are before 'grep' finds the binary data.
See the following example, which should hopefully make it a bit more
clear:
$ yes a | head -n $((1024 * 1024 * 128)) > input
$ printf '\0' >> input
$ LC_ALL=C grep '^a$' input | wc -l
grep: input: binary file matches
134184960
Collin
[1]
https://www.gnu.org/software/grep/manual/html_node/File-and-Directory-Selection.html#index-_002d_002dbinary_002dfiles