grepテキストの場合のバイナリファイルの標準入力の一致の問題を解決します



Solve Problem Binary File Standard Input Matches When Grep Text



今日、grepはログファイルを作成し、「バイナリファイル(標準入力)の一致」を報告しました

[root@xxxxx pagent_server]# cat /tmp/pcap/log/agent_server.log |grep 8887 Binary file (standard input) matches

viでファイルを開いて見てみると、文字化けしていない文字があります



[root@xxxxx pagent_server]# vi /tmp/pcap/log/agent_server.log 2019/12/24 18:07:57.742 [I] Agent[127.0.0.1:33526] Alert info ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^

この問題は、grepに--textまたは-aを追加することで解決できます。

[root@xxxxx pagent_server]# cat /tmp/pcap/log/agent_server.log |grep --text 8887 2019/12/24 18:08:04.527 [I] New connect 8887 from 127.0.0.1:36927 2019/12/24 18:08:34.528 [I] New connect 8887 from 127.0.0.1:36934 2019/12/24 18:09:04.530 [I] New connect 8887 from 127.0.0.1:36939