The alternation operator is used to specify alternatives. The alternation operator is a vertical bar or pipe symbol, it matches one regular expression out of several regular expressions. The '|' alternation operator has the lowest precedence among all the regular expression operators. For example, in the employee database, if we want to print the lines that have first name of the employee as Emily, Jack, or Ana, we can write the following regular expression:
$ awk '/Emily|Jack|Ana/' emp.dat
In AWK, it is generally used with the ( ) grouping operator, as follows:
$ awk '/(Emily|Jack|Ana)/' emp.dat
The output on execution of the given code is as follows:
Jack Singh 9857532312 email@example.com M hr 2000Ana Khanna 9856422312 ...