[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
grep: 'binary files' where matches are text
From: |
eavis |
Subject: |
grep: 'binary files' where matches are text |
Date: |
Wed, 5 Feb 2003 16:34:29 +0000 |
It's useful that GNU grep, by default, avoids printing binary garbage to
the terminal by skipping over files that it considers 'binary'. But
surely the important issue is not whether the file contains binary data,
but whether the matches found are printable.
I would like to suggest a new option, although I do not know what it
should be called:
--foo
Search all files for matches, even binary files, but if a match is
found that contains binary data just print a message 'match containing
binary data in file X' instead of printing that match.
This is subtly different from the current behaviour of grep, which will
summarize the whole file with 'matches found' even if most of those
matches could be safely printed. In fact, I would even venture to say
that this behaviour should be the default, since it prints as many matches
as possible without generating unprintable characters.
Perhaps this option could fit into the existing --binary-files choices:
--binary-files=print_text_matches or some such. But (opinion) I don't
think the --binary-files option is a particularly neat or self-explanatory
way of presenting these choices. As I said above, what really matters is
whether the _matches_ are binary, not the input files. Perhaps a single
Boolean option for 'print binary matches' would cover most needs.
BTW, what prompted me to suggest this was:
% set | grep FRED
Binary file (standard input) matches
% set | grep --text FRED
FRED=fred
There was no need for grep to be so reticent, just because there were a
few binary characters in the output of 'set' amid a much larger amount of
ASCII text.
--
Ed Avis <address@hidden>
- grep: 'binary files' where matches are text,
eavis <=