Pipe output to use as the search specification for grep on Linux

前端 未结 9 1113
天涯浪人
天涯浪人 2021-02-03 22:12

How do I pipe the output of grep as the search pattern for another grep?

As an example:

grep   | xargs grep          


        
9条回答
  •  别那么骄傲
    2021-02-03 22:40

    I wanted to search for text in files (using grep) that had a certain pattern in their file names (found using find) in the current directory. I used the following command:

     grep -i "pattern1" $(find . -name "pattern2")
    

    Here pattern2 is the pattern in the file names and pattern1 is the pattern searched for within files matching pattern2.

    edit: Not strictly piping but still related and quite useful...

提交回复
热议问题