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

前端 未结 9 1129
天涯浪人
天涯浪人 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:47

    This is what I use to search for a file from a listing:

    ls -la | grep 'file-in-which-to-search'
    
    0 讨论(0)
  • 2021-02-03 22:53

    I tried this way , and it works great.

    [opuser@vjmachine abc]$ cat a
    not problem
    all
    problem
    first
    not to get
    read problem
    read not problem
    
    [opuser@vjmachine abc]$ cat b
    not problem xxy
    problem abcd
    read problem werwer
    read not problem  98989
    123 not problem 345
    345 problem tyu
    
    [opuser@vjmachine abc]$ grep -e "`grep problem a`" b --col
    not problem xxy
    problem abcd
    read problem werwer
    read not problem  98989
    123 not problem 345
    345 problem tyu
    
    [opuser@vjmachine abc]$ 
    
    0 讨论(0)
  • 2021-02-03 22:55

    I have found the following command to work using $() with my first command inside the parenthesis to have the shell execute it first.

    grep $(dig +short) file
    

    I use this to look through files for an IP address when I am given a host name.

    0 讨论(0)
提交回复
热议问题