2
2
How can i combine find
and grep
to search for str1
or str2
, recursively, in all *.html and *.php files starting from a directory named /home/smith/source? The output only needs to list files (with path), not the actual matched string. i've tried many variations without success. There are lots of examples of how to do this for one file pattern or one string, but not multiple file patterns and multiple strings--recursively.
That shows matched text, not filenames, but that's OK (I made the update to the questions probably while you were answering the existing one). How can I generalize this if i want to search 3,4,5, or n file patterns? – None – 2013-03-29T01:02:23.923
-H option of egrep then to output filepaths. str1|str2|str3..etc would work - is that what you mean by generalize? – suspectus – 2013-03-29T01:06:37.687
Yes, but I also meant to generalize the file pattern (e.g., *.php and *.html and .txt and ...). This appears to do it: `find /home/smiths/source -type f -regextype posix-egrep -regex "..(php|html)$" -exec egrep -H -n "str1|str2|str3" '{}' ;` – None – 2013-03-29T01:42:26.157