태그 보관물: parsing

parsing

텍스트처럼 보이는 이진 파일을 어떻게 grep합니까? 수는 없습니다 (보기

텍스트 인 바이너리 파일이 있지만 로그를 내보냈지만 덜 열 수는 없습니다 (보기 흉한 모양-바이너리 파일처럼 보입니다). 나는 vi로 그것을 열 수 있고 그것을 고양이로 만들 수 있다는 것을 발견했다. 검색). 내가 할 수있는 방법이 있습니까?



답변

grep어쨌든 파일을 검색 하는 데 사용할 수 있습니다 . 입력 파일이 실제로 텍스트인지 아닌지는 신경 쓰지 않습니다. ‘남자 grep’에서 :

    -a, --text
          Process a binary file as if it were text; this is equivalent to the --binary-files=text option.

   --binary-files=TYPE
          If  the  first few bytes of a file indicate that the file contains binary data, assume that the file is
          of type TYPE.  By default, TYPE is binary, and grep normally outputs either a one-line  message  saying
          that a binary file matches, or no message if there is no match.  If TYPE is without-match, grep assumes
          that a binary file does not match; this is equivalent  to  the  -I  option.   If  TYPE  is  text,  grep
          processes  a  binary  file  as  if  it  were  text; this is equivalent to the -a option.  Warning: grep
          --binary-files=text might output binary garbage, which can have nasty side effects if the output  is  a
          terminal and if the terminal driver interprets some of it as commands.

두 번째 단락 끝에주의 표시를하십시오. grep의 결과를 새 파일로 리디렉션하고 vi / less로 검사 할 수 있습니다.


답변

그것을 통해 파이프 strings하면 텍스트 만 남기고 모든 바이너리 코드가 제거됩니다.


답변

부여 bgrep시도. ( 원래 출시 / 최신 포크 )


답변

이 세 가지 명령을 사용할 수 있습니다.

  1. grep -a <sth> file.txt

  2. cat -v file.txt | grep <sth>

  3. cat file.txt | tr '[\000-\011\013-\037\177-\377]' '.' | grep <sth>


답변

Grep 2.21부터 이진 파일은 다르게 취급됩니다 .

이진 데이터를 검색 할 때 grep은 이제 비 텍스트 바이트를 줄 종결 자로 취급 할 수 있습니다. 이것은 성능을 크게 향상시킬 수 있습니다.

따라서 이제 이진 데이터를 사용하면 텍스트가 아닌 모든 바이트 (줄 바꾸기 포함)가 줄 종결 자로 처리됩니다. 이 동작을 변경하려면 다음을 수행하십시오.

  • 사용하십시오 --text. 이렇게하면 개행 만 줄 종결자가됩니다.

  • 사용하십시오 --null-data. 이렇게하면 null 바이트 만 줄 종결자가됩니다.


답변