Read expression for grep from standard input

后端 未结 1 1543
野的像风
野的像风 2020-12-28 11:57

How can I make grep read the expression from standard input (stdin)?

For example (the following doesn\'t work):

grep -i -f &0 /p         


        
相关标签:
1条回答
  • 2020-12-28 12:49

    Use -f with a single dash to denote the standard input:

    $ echo Content | grep -f - notice.html 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    ...
    

    Note: This has been tested with GNU grep - I am not sure if it's specified by POSIX.

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