Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep 'binary file matches'. How to get normal grep output? [duplicate]

Tags:

grep

bash

I've got a grep script that searches through a directory recursively.

grep -n -R -e 'search term' -e 'second search term' ./  

However the results I get are the following. Notice there are found matches in JPGs but no actual result.

Binary file ./jpg/00015928.jpg matches Binary file ./jpg/00015296.jpg matches Binary file ./jpg/00020072.jpg matches 

Is there any way to see the result in the output like a normal grep search?

like image 409
davidbain Avatar asked May 07 '14 08:05

davidbain


People also ask

Does grep work on binary files?

If type is ' text ', grep processes binary data as if it were text; this is equivalent to the -a option. When type is ' binary ', grep may treat non-text bytes as line terminators even without the -z ( --null-data ) option. This means choosing ' binary ' versus ' text ' can affect whether a pattern matches a file.

Why does grep say binary file matches?

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.

What does binary file matches mean?

Binary file [some_file] matches. ...this is what's happening... [from the grep man page] Normally, if the first few bytes of a file indicate that the file contains binary data, grep outputs only a message saying that the file matches the pattern. To force the file to be treated as text, use the -a (or --text) option.

How do I grep text in binary?

You can also use the “grep –a” command combined with the “cat” command as shown below. Let's use the alternative “—binary-files=text” of the “-a” option for the grep command on the 'new.sh' binary file. It shows the same output as we got for the “-a” option.


1 Answers

Try:

grep --text 

or

grep -a  

for short. This is equivalent to --binary-files=text and it should show the matches in binary files.

like image 94
perreal Avatar answered Oct 16 '22 10:10

perreal