On 09/21/2013 04:46 PM, ken wrote:
I could be wrong, but doesn't egrep, which supports extended regular expressions, fit the bill?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 successfulI 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 thesearch to files that also contain "word2" man grep for options. But you might be interested in '-r' to recursively search a path. -RobRob,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
=; echo two words > grep-AND-test1 =; echo two > grep-AND-test2 =; echo words >> grep-AND-test2 =; egrep 'two|words' grep-AND-test* grep-AND-test1:two words grep-AND-test2:two grep-AND-test2:words