Grep 如何在某些同名文件中查找文本

Grep 如何在某些同名文件中查找文本,grep,find,Grep,Find,我在几个目录中有一些名为savedsearchs.conf的文件,我需要知道savedsearchs.conf在哪个目录中有一个字符串(即“search1”)。 我试着指挥 find /opt/splunk/ -name "savedsearches.conf" -exec grep -i "search1" {} \; 但通过这种方式,我只能看到包含“search1”的文本,但我不知道包含文本的文件的路径 我想要路径、文件名和字符串。可以吗?使用-H选项 find /opt/splunk/

我在几个目录中有一些名为savedsearchs.conf的文件,我需要知道savedsearchs.conf在哪个目录中有一个字符串(即“search1”)。 我试着指挥

find /opt/splunk/ -name "savedsearches.conf" -exec grep -i "search1" {} \;
但通过这种方式,我只能看到包含“search1”的文本,但我不知道包含文本的文件的路径


我想要路径、文件名和字符串。可以吗?

使用
-H
选项

find /opt/splunk/ -name "savedsearches.conf" -exec grep -iH "search1" {} \;
示例输出:

/opt/splunk/savedsearches.conf:search1

这是使用btool的完美案例


/opt/splunk/bin/splunk btool savedsearches.conf list-debug | grep search1

此类问题属于完美!谢谢!如果您喜欢此答案,请将其标记为已接受,以便其他人知道您的问题已解决。