如何在grep中closures二进制文件匹配结果

当在linux中使用grep时,结果总是包含很多“二进制文件XXX匹配”,我不在乎。 如何压制这部分结果,或者如何排除grep中的二进制文件?

有三个选项,你可以使用。 -I是排除grep中的二进制文件。 其他是用于行号和文件名。

 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 

所以这可能是一个运行grep的方法:

 grep -InH your-word * 

这是一个古老的问题,已经回答了,但是我想我会把–binary-files = text选项放在这里给任何想要使用它的人。 -I选项会忽略二进制文件,但是如果您希望grep将二进制文件视为文本文件,请使用–binary-files = text,如下所示:

 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$