I want to search a file with either this string 'foo' or this string 'bar'. This is what I've attempted so far:
cat filename.csv | grep foo\|bar
You can specify multiple patterns with multiple -e
flags:
grep -e foo -e bar filename.csv
This is a POSIX standard.
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与正则表达式一起使用。
cat filename.csv | egrep 'foo|bar'
You can use any of following.
cat filename.csv | grep -E 'foo|bar'
grep -E 'foo|bar' filename.csv
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.