a question about GREP
Python
python at venix.com
Fri Mar 23 17:37:39 EDT 2007
On Fri, 2007-03-23 at 15:41 -0400, Jerry wrote:
> Hi,
>
> The manual of "grep" command on Red Hat states that:
>
> -R, -r, --recursive
> read all files in each directory, recursively, this is
> equivalent to -d recurse option
>
> --include=PATTERN recurse in directories only searching file
> matching PATTERN
> --exclude=PATTERN recurse in directories skip file matching
> PATTERN
>
> For the --include or --exclude option, what is "file matching PATTERN"
> supposed to mean? I supposed it means "file name" match PATTERN, not
> "file content" match patten, am I right?
>
> I'm asking this question, because I'm trying to do the following
> thing:
>
> Find out all plain text files whose file names contain "out" and whose
> contents containing "zip" (in the form of whole word), and then
> output these files names to a file called zip.txt. (These plain text
> files are located in the sub-directories at different levels)
Would this approach work?
find -type f -name '*out*' | xargs grep -wli zip > zip.txt
use find to recurse through directories and create a list of files.
xargs feeds the file list as arguments to grep.
grep examines the files looking for the word zip ignoring case
and writes the filenames
which get directed into zip.txt
>
> I tried the following 2 lines of commands to try to achieve the goal
> above, but neither worked. Anyone cares to spot the error? I suspect
> most likely it's because my usage/understanding of --include option is
> wrong.
>
> grep -Hwli -r --include=out "zip" * > zip.txt
>
> grep -Hwli --include=out "zip" * > zip.txt
>
> Sorry if this question sounds stupid.
>
> Thank you for your time.
>
> Zhao
> _______________________________________________
> gnhlug-discuss mailing list
> gnhlug-discuss at mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
--
Lloyd Kvam
Venix Corp
More information about the gnhlug-discuss
mailing list