如何将一次 ag 搜索找到的文件用作第二次 ag 搜索的域?
How can I use the files found by one ag search as the domain for a second ag search?
假设我ag -l foo
。这让我得到了一个文件列表。
我怎样才能再次使用 ag 只在这些文件中搜索?
假设您在 bash shell 中,您可以这样做:
ag whatever $(ag -l foo)
所以要找到同时匹配 cat 和 dog 的所有文件:
ag cat $(ag -l dog)
您也可以使用 xargs
:
ag -l dog | xargs ag cat
如果您使用了另一个 greplike 工具 ack
,您可以使用 -x
选项从标准输入读取输入文件列表:
ack -l dog | ack -x cat
假设我ag -l foo
。这让我得到了一个文件列表。
我怎样才能再次使用 ag 只在这些文件中搜索?
假设您在 bash shell 中,您可以这样做:
ag whatever $(ag -l foo)
所以要找到同时匹配 cat 和 dog 的所有文件:
ag cat $(ag -l dog)
您也可以使用 xargs
:
ag -l dog | xargs ag cat
如果您使用了另一个 greplike 工具 ack
,您可以使用 -x
选项从标准输入读取输入文件列表:
ack -l dog | ack -x cat