How to grep file containing some binary characters?

2

One application sometimes, not very often, puts some incorrect (binary) characters in log. Only information that it matches is printed, no matched lines.

$ grep -e error app.log 
Binary file app.log matches

How can I grep the log simply omitting the binary characters?

less handles the file correctly, prints the binary characters as some escape sequences, so maybe some pipe less to grep will solve the issue.

user2622016

Posted 2013-11-08T11:58:18.693

Reputation: 123

Answers

1

You can tell grep to interpret the source file as a text file:

grep -a -e error app.log

Take into account that grep will not escape the binary characters so you should pipe the output to less or od -c to prevent possible negative effects of the characters to the terminal.

pabouk

Posted 2013-11-08T11:58:18.693

Reputation: 5 358