egrep "foo|bar" *.txt
या
grep "foo\|bar" *.txt
grep -E "foo|bar" *.txt
चुनिंदा तौर पर gnu-grep के मैन पेज का हवाला देते हुए:
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified by POSIX.)
Matching Control
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern
beginning with a hyphen (-). (-e is specified by POSIX.)
(...)
grep understands two different versions of regular expression syntax: “basic” and “extended.” In GNU grep, there
is no difference in available functionality using either syntax. In other implementations, basic regular
expressions are less powerful. The following description applies to extended regular expressions; differences for
basic regular expressions are summarized afterwards.
शुरुआत में मैंने आगे नहीं पढ़ा, इसलिए मैंने सूक्ष्म अंतरों को नहीं पहचाना:
Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the
backslashed versions \?, \+, \{, \|, \(, and \).
मैंने हमेशा egrep और अनावश्यक रूप से parens का उपयोग किया, क्योंकि मैंने उदाहरणों से सीखा। अब मैंने कुछ नया सीखा। :)