Read expression for grep from standard input

2019-02-04 01:56发布

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

For example (the following doesn't work):

grep -i -f &0 /path/to/text/file < "/regexp/"

标签: grep stdin
1条回答
萌系小妹纸
2楼-- · 2019-02-04 02:08

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.

查看更多
登录 后发表回答