Read expression for grep from standard input

ε祈祈猫儿з 提交于 2019-12-30 00:27:15

问题


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/"

回答1:


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.



来源:https://stackoverflow.com/questions/6641731/read-expression-for-grep-from-standard-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!