Programing

grep에서 이진 파일 일치 결과를 억제하는 방법

lottogame 2020. 5. 19. 08:07
반응형

grep에서 이진 파일 일치 결과를 억제하는 방법


grep리눅스에서 사용할 때 , 결과는 종종 많은 "이진 파일 XXX 일치"를 포함하는데, 나는 상관하지 않습니다. 결과 의이 부분을 억제하는 방법 또는 grep에서 이진 파일을 제외하는 방법은 무엇입니까?


사용할 수있는 세 가지 옵션이 있습니다. -Igrep에서 이진 파일을 제외하는 것입니다. 다른 라인 번호와 파일 이름입니다.

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$

참고 URL : https://stackoverflow.com/questions/25853722/how-to-suppress-binary-file-matching-results-in-grep

반응형