[英]How can I grep a file using OR
I want to search a file with either this string 'foo' or this string 'bar'. 我想使用此字符串'foo'或此字符串'bar'搜索文件。 This is what I've attempted so far: 到目前为止,这是我尝试过的:
cat filename.csv | grep foo\|bar
You can specify multiple patterns with multiple -e
flags: 您可以使用多个-e
标志指定多个模式:
grep -e foo -e bar filename.csv
This is a POSIX standard. 这是POSIX标准。
What I suggested earlier does not work on some installations. 我先前建议的内容不适用于某些安装。 I believe this is a more portable syntax: 我相信这是一种更可移植的语法:
grep -E 'foo|bar' filename.csv
The above is an alternative form of: 上面是另一种形式:
egrep 'foo|bar' filename.csv
egrep supports use of a regular expression, which in this case is 'foo|bar' egrep支持使用正则表达式,在这种情况下为“ foo | bar”
将egrep与正则表达式一起使用。
cat filename.csv | egrep 'foo|bar'
You can use any of following. 您可以使用以下任何一种。
cat filename.csv | 猫filename.csv | grep -E 'foo|bar' grep -E'foo | bar'
grep -E 'foo|bar' filename.csv grep -E'foo | bar'filename.csv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.