Let's say there is the following tree of directories:
foo/
+bar/
| +VIEW/
| | +other/
| | +file.groovy
| | +file2.groovy
| | +file.txt
| +file3.groovy
+xyz/
+VIEW/
+file4.groovy
+file5.groovy
And I want to grep method
only on groovy files that are into any directory that either is VIEW or is under VIEW (that would be file.groovy, file2.groovy and file4.groovy).
I'm trying to do so using --include=.*\/VIEW\/.*\.groovy
which as far as I know is the regex for anything and then / character and then the word VIEW and then / character and then anything and then the word .groovy
But that actually doesn't return anything.
Isn't there a way of doing this using the include
option?
From the UNIX philosophy:
Write programs that do one thing and do it well. Write programs to work together.
I don't like the GNU extension for recursive directory searching. The tool find
does a much better job, has a cleaner syntax with more options and doesn't break the philosophy!
$ find foo/*/VIEW -name "*.groovy" -exec grep method {} \;
Specifying the -path
option for find
should work:
find foo/ -path "*/VIEW/*" -name "*.groovy" -exec grep method {} \;
You don't need to provide directory path in include=
option, just provide the path as last argument to recursive grep.
Thus you can simply do:
grep -R 'method' --include=*.groovy foo/bar/VIEW/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With