On Friday, Mar 23rd 2007 at 15:41 -0400, quoth Jerry:

=>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)
=>
=>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.

That's the dumbest question I ever heard! (just kidding)

It seems to me that you need grep find awk xargs etc...

Tell me if this helps:

find . -type f -name \*out\* | \
 xargs file | \
 awk '/ASCII/ { sub(/:/, ""); print $1}' | \
 xargs grep -l zip > zip.txt

Line 1 gets the list of files whose name contains the word "out".
Line 2 takes that list and runs the file command
Line 3 takes the output of file and prints out column 1 (without the colon 
       at the end) if the word ASCII is found
Line 4 takes the previous output and searches those files for the word zip 
and the output then goes into zip.txt

Easy peasy japaneezy

(I shall now buff my nails.)

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

Reply via email to