[lug] Grep question

David Morris lists at morris-clan.net
Fri Jul 23 11:31:23 MDT 2004


On Fri, Jul 23, 2004 at 03:46:23AM -0600, Daniel Webb wrote:
> On Thu, 22 Jul 2004, Joey McDonald wrote:
> 
> > I usually do something like:
> >
> > find /dir/to/search -type f | xargs -n1 grep -l string $1
> 
> I don't see how that finds the string inside a gzipped text file.

An alternate to that line which does the same thing:

  find /dir/to/search -type f -exec zgrep -l "searchstring" {} \;

(or whatever command you want in place of
'zgrep -l "searchstring"').

xargs is more generically powerful, but in this case it is
overkill.

> Come to think of it, what I really want is to be able to grep inside any
> kind of file or archive that can possibly be converted to text (for
> example, something.pdf.gz could be gunzipped, then pdftotext used to
> convert to text).  Does THAT exist?

No that does not exist, but it would be relatively simple to
create a script which does that for known file types.  Just
a list of if-then-else statements to handle various file
types and convert them to text before doing the grep
(piping everything through stdout/stdin when possible to
avoid unneeded temporary files).  The 'file' program can be
of particular use here in determining what type each input
file really is.

--David




More information about the LUG mailing list