When using grep in Linux, the output frequently contains a large number of “binary file XXX matches,” which I ignore. How can this part of the results be suppressed, or how may binary files be excluded in grep?
Asked by RandyTek
There are three alternatives available to you. In grep, the -I option is used to exclude binary files. Line numbers and file names are among the others.
grep -I -n -H -I -- process a binary file as if it did not contain matching data; -n -- prefix each line of output with the 1-based line number within its input file -H -- print the file name for each match
So here’s one way to execute grep:
grep -InH your-word *
Answered by 2 revs, 2 users 96% user184968
Although this is an old question that has already been answered, I thought I’d include the —binary-files=text option here in case anyone else is interested. The -I option ignores the binary file, but you can use —binary-files=text to make grep treat the binary file as a text file:
bash$ grep -i reset mediaLog* Binary file mediaLog_dc1.txt matches bash$ grep --binary-files=text -i reset mediaLog* mediaLog_dc1.txt:2016-06-29 15:46:02,470 - Media [uploadChunk ,315] - ERROR - ('Connection aborted.', error(104, 'Connection reset by peer')) mediaLog_dc1.txt:ConnectionError: ('Connection aborted.', error(104, 'Connection reset by peer')) bash$
Answered by amadain
Post is based on https://stackoverflow.com/questions/25853722/how-to-suppress-binary-file-matching-results-in-grep