grep

Jon H. LaBadie jon at jonlab.UUCP
Sat Oct 27 02:18:19 AEST 1990


In article <2160 at sixhub.UUCP>, davidsen at sixhub.UUCP (Wm E. Davidsen Jr) writes:
> Lots of people have given you ideas on this,

Indeed, but I've seen no one mention the use of the '-l' option to grep.
The original poster wanted to locate the "files" that contained the
pattern, not the "lines" containing the pattern.  By using the -l option,
grep will simply output a list of the file names.  An added benefit is
that grep will skip the rest of the current file once it finds a match.

> ... I'll just add that if you
> have a large number of non-text files in this structure, you can save
> time by using the "file" command to identify the text files.
> 
> Something like:
> 
>     $ find . -type f -print | xargs file | grep " text" |
>     > sed 's/:.*$//' | xargs grep PATTERN /dev/null
> 

Just a comment specific to AIX 3.1.
The common practice of looking for text files using

	file * | grep " text"

does not work properly as some output messages contain the word
"text" even though the file is a binary or data file.  For example,
one message I remember is "data or NLS text".

-- 
Jon LaBadie
{att, princeton, bcr, attmail!auxnj}!jonlab!jon



More information about the Comp.unix.questions mailing list