How to suppress binary file matching results in grep [closed] How to suppress binary file matching results in grep [closed] linux linux

How to suppress binary file matching results in grep [closed]


There are three options, that you can use. -I is to exclude binary files in grep. Other are for line numbers and file names.

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 this might be a way to run grep:

grep -InH your-word *


This is an old question and its been answered but I thought I'd put the --binary-files=text option here for anyone who wants to use it. The -I option ignores the binary file but if you want the grep to treat the binary file as a text file use --binary-files=text like so:

bash$ grep -i reset mediaLog*Binary file mediaLog_dc1.txt matchesbash$ 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$