Skip to content

bzgrep on binary files shows "(standard input)" instead of filename

When using bzgrep to search for a match in binary files it outputs "standard input)" instead of the filename. This is obviously not very useful.

To test:

head -c 2000 /dev/urandom > a.bin
head -c 2000 /dev/urandom > b.bin
head -c 2000 /dev/urandom > c.bin
echo abcdefg >> a.bin
echo abcdefg >> c.bin
bzip2 a.bin b.bin c.bin
bzgrep abcdefg *.bz2

Output:

grep: (standard input): binary file matches
grep: (standard input): binary file matches

I would expect the filenames a.bin.bz2 and c.bin.bz2 in the output. The zgrep and xzgrep tools do this as expected (as does plain grep), e.g. if I adapt above example to gzip/zgrep I get:

/bin/grep: a.bin.gz: binary file matches
/bin/grep: c.bin.gz: binary file matches