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?
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.
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.
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.
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.
Try:
grep --text
or
grep -a
for short. This is equivalent to --binary-files=text
and it should show the matches in binary files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With