Reputation: 2830
I would like a list of the filenames of files containing the word "hot" (don't care about case). The files should also be under the directory /test/home, with filenames starting with "config".
grep -ilrw "hot" * | grep -i config
Another disadvantage of this approach is that it is not possible to check for filenames starting with "config". For example, "grep -i ^config" will not match files such as "/test/home/configurations/config.xml"
Is there a way to work round this?
grep -ilrw "hot" config*
Upvotes: 2
Views: 9576
Reputation: 15157
If you are looking to use only grep you weren't far off. I'd do;
grep -Rli --include='config*' "hot" *
--include, allows you to specify a GLOB to search and the final * allows you to tweak the files/directories that the include glob will work on.
Upvotes: 4
Reputation: 136208
If you are a lucky user of GNU powertools, find can do that for you:
find /test/home -iregex ".*hot.*" -regex "config.*"
Upvotes: 0
Reputation: 3472
find . -name 'config*' | xargs grep -i "hot"
may depend a bit on your flavor of UNIX, I think
Upvotes: 4