I'd guess it has something to do with how grep sees the binary stream, but I don't really know. You might want to try using the
-a option instead.
As another option, how about using
strings to extract the raw text, and grepping that? You'll have to run it in a loop to get the filenames, however.
This will print out any files that contain "Cons" as a text string, in the same format as
grep -c.
Code:
for f in *.xls; do
c=$( strings "$f" | grep -c "Cons" ) && echo "$f:$c"
done
Change the "
&&" to "
;" if you want it to print out the results of all the files.
If all you really want is to know which files match, and you don't care about the actual count, you can shorten it a bit:
Code:
for f in *.xls; do
strings "$f" | grep -q "Cons" && echo "$f"
done