从标准输入读取 grep 的表达式 [英] Read expression for grep from standard input

查看:16
本文介绍了从标准输入读取 grep 的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让 grep 从标准输入 (stdin) 读取表达式?

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

推荐答案

使用 -f 和一个破折号来表示标准输入:

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

注意:这已经用 GNU grep 测试过 - 我不确定它是否由 POSIX 指定.

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

这篇关于从标准输入读取 grep 的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆