a question about GREP
mike ledoux
mwl+gnhlug at alumni.unh.edu
Mon Mar 26 12:36:12 EDT 2007
On Mon, Mar 26, 2007 at 11:38:31AM -0400, Jerry wrote:
> Lloyd (python at venix.com)'s solution works:
>
> find -type f -name '*out*' | xargs grep -wli zip > zip.txt
>
> Question: "-type f" limits to "regular file", does the so-called "regular
> file" strictly mean "plain text files"?
It does not. "regular file" means not a special file, directory,
named pipe, symbolic link, or socket. "plain text files" are a
subset of "regular files". If you just want to omit non-text files
from the output, something like:
find . -type f -name '*out*' -print0 | xargs -0 grep -wliI zip > zip.txt
will probably do what you want. The -I option to GNU grep tells it
to treat binary files as if they contain no matches. The -print0
to find and -0 to xargs improve handling of file names that contain
whitespace.
> Steven's solution (listed below) only partially works, for reasons I don't
> know. By "partially", I mean his solution can only find SOME files matching
> the search criteria.
>
> find . -type f -name \*out\* | \
> xargs file | \
> awk '/ASCII/ { sub(/:/, ""); print $1}' | \
> xargs grep -l zip > zip.txt
If you run 'find . -type f -name '*out*' -print0 | xargs -0 file'
I bet some of the files you are calling "plain text files" are not
"ASCII text files", which is what the above is looking for. For
example, a file 'file' reports as "ISO-8859 English text" will
almost certainly meet *your* critera for "plain text", but doesn't
include "ASCII" anywhere in the output of 'file'.
--
mwl+gnhlug at alumni.unh.edu OpenPGP KeyID 0x57C3430B
Holder of Past Knowledge CS, O-
"Working on Megatokyo is a lot like trying to fix the engine on a bus while
it cruises down a bumpy highway at 75 mph with two monkeys fighting over
the steering wheel and a brick on the accelerator." Piro
More information about the gnhlug-discuss
mailing list