【问题标题】:How can I search for a file that contains a pattern and then search within all those files with another pattern?如何搜索包含一个模式的文件,然后在所有这些文件中搜索另一个模式?
【发布时间】:2014-02-04 15:29:10
【问题描述】:

基本上,我想做这样的事情:

Locate log4j.xml 

这会给我超过 20 个结果。然后我想在所有这些文件中搜索“iwjboss”。

考虑到我不知道所有 log4j.xml 文件的目录,是否有一个命令可以在所有这些文件中定位并查找文本?

【问题讨论】:

    标签: linux shell unix command


    【解决方案1】:

    用某事的结果做某事是这样实现的:

    grep iwjboss `locate log4j.xml`
    

    【讨论】:

      【解决方案2】:

      是的,有一个命令叫做find

      试试这个命令,把 find 和 grep 结合起来:

      find . -name "log4j.xml" -exec grep "iwjboss" '{}' \;
      

      【讨论】:

        猜你喜欢
        • 2013-12-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-25
        • 2017-12-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多