Cómo suprimir los resultados de coincidencia de archivos binarios en grep [cerrado]


Cuando se usa grep en linux, el resultado siempre contiene una gran cantidad de "coincidencias XXX de archivos binarios", que no me importan. Cómo suprimir esta parte de los resultados, o cómo excluir archivos binarios en grep?

 126
Author: RandyTek, 2014-09-15

2 answers

Hay tres opciones que puedes usar. -I es excluir archivos binarios en grep. Otros son para números de línea y nombres de archivo.

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

Así que esta podría ser una forma de ejecutar grep:

grep -InH your-word *
 171
Author: Sergei Kurenkov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-16 10:26:07

Esta es una pregunta antigua y ha sido respondida, pero pensé en poner la opción binary binary-files=text aquí para cualquiera que quiera usarla. La opción-I ignora el archivo binario, pero si desea que el grep trate el archivo binario como un archivo de texto, use binary binary-files = text like so:

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$
 7
Author: amadain,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-29 14:58:45