如何在模式路径下grep文件

Alf*_*gon 4 unix grep

假设有以下目录树:

foo/
   +bar/
   |   +VIEW/
   |   |    +other/
   |   |          +file.groovy
   |   |    +file2.groovy
   |   |    +file.txt
   |   +file3.groovy
   +xyz/
       +VIEW/
            +file4.groovy
       +file5.groovy
Run Code Online (Sandbox Code Playgroud)

而且我只想method在任何目录中的常规文件上进行grep ,这些目录是VIEW或者在VIEW下(即file.groovy,file2.groovy和file4.groovy).

我正在尝试这样做--include=.*\/VIEW\/.*\.groovy,据我所知是正则表达式的任何东西然后/字符然后单词VIEW然后/字符然后任何东西然后单词.groovy

但实际上并没有返回任何东西.

是不是有办法使用该include选项?

Chr*_*our 5

UNIX哲学:

编写做一件事并做得好的程序.编写程序以协同工作.

我不喜欢递归目录搜索的GNU扩展.该工具find做得更好,语法更清晰,有更多选项,并没有打破哲学!

$ find foo/*/VIEW -name "*.groovy" -exec grep method {} \;   
Run Code Online (Sandbox Code Playgroud)


dev*_*ull 3

指定 的-path选项find应该有效:

find foo/ -path "*/VIEW/*" -name "*.groovy" -exec grep method {} \;
Run Code Online (Sandbox Code Playgroud)