[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: find'ing files containing certain words (all of them) ...



On 09/21/2013 07:56 AM Rob Owens wrote:
On Sat, Sep 21, 2013 at 05:22:09AM -0400, Albretch Mueller wrote:
  the short bash script bellow you can use to find text files
containing one word, but my attempts at trying to make it find more
than one word within the same file haven't been successful

I think you are looking for the 'grep' command.

"grep word path/*" will find all files in "path" which contain "word"

"grep word path/* | grep word2" will do the same, but then narrow down the
search to files that also contain "word2"

man grep for options.  But you might be interested in '-r' to
recursively search a path.

-Rob

Rob,

This is incorrect, though it's a common misconception. It will only work if both of the words sought are on the same line within in the sought files. This isn't what the OP is asking for.

Instead:

$ echo two words > grep-AND-test1
$ echo two > grep-AND-test2
$ echo words >> grep-AND-test2
$ grep -l words $(grep -l two *)
grep-AND-test1
grep-AND-test2



Reply to: