@hussam:
First, you don't need to use `find`, since you can use `grep -r` which will traverse directories recursively.[1]
Second, your question is asking to list files containing patterns, but the commands you run are actually listing pattern matches, not filenames.
If you want to list the name of the files matching your pattern, you have to use these options:
man grep(1) wrote -L, --files-without-match
Suppress normal output; instead print the name of each input
file from which no output would normally have been printed. The
scanning will stop on the first match.
-l, --files-with-matches
Suppress normal output; instead print the name of each input
file from which output would normally have been printed. The
scanning will stop on the first match.
In your case, try something like this:
grep -rl 'string1:' . | xargs grep -L 'string1: string2'
It's pretty close to
your suggestion, but arguably a bit faster, if the second grep is running on a considerably smaller subset (which is highly likely).
[1]: About traversing directories recursively, you can also get by using shell features. If you're using a modern shell (like zsh or bash 4), you can use the really cool
recursive globbing feature. (Note that by default, OS X uses bash 3, which is political and idiotic, but that's a rant for another day...). Anyway, my point is that you should avoid Useless Uses of Find. A good rule of thumb is, every time you use `find .`, there's probably a better way to do it.