Selective operation
Vertical bar (|) Characters are part of a meta-character extension set that specifies the Union of regular expressions. If a row matches one of the regular expressions, it matches the pattern. For example, the regular expression: unix| Linux
The line that contains the string "UNIX" or the string "LINUX" will be matched. You can specify more choices, such as:
Unix| Linux| NETBSD
When using Egrep, prints a line that matches any of these 3 modes.
In sed, there are no union metacharacters, and each mode can be specified separately. In the following, we will consider the operations of the grouping, and we will see additional columns about the metacharacters.
grouping operations The
parentheses () are used to group and prioritize regular expressions. They are part of the meta-character expansion set. Suppose the name of the company in the text file is "Bigone" or "Bigone computer", using an expression:
Bigone (computer)?
Matches the string "Bigone" itself or follows the form of a string "computer". Similarly, some terms are sometimes used in full spelling, sometimes abbreviated, and can be used:
$ egrep "Lab (oratorie)? s" Mail.list
Bell Laboratories, Lucent Technologies
Bell Labs
You can use vertical bars and parentheses to group selective operations. In the following example, we use it to specify a singular or plural match to the word "Company".
Compan (y|ies)
Note that in most sed and grep versions, you cannot apply a number of words to a set of parentheses, but are available in all versions of Egrep and awk.
Reference: http://www.linuxawk.com/communication/455.html
Linux Regular Expressions-selective operations and grouping operations