|
|
A compound pattern combines simpler patterns with parentheses and the logical operators || (OR), && (AND), and ! (NOT). For example, if you want to print all countries in Asia with a population of more than 500 million, use the following program:
$4 == "Asia" && $3 > 500This program selects all lines in which the fourth field is Asia and the third field exceeds 500.
The following program selects lines with the strings ``Asia'' or ``Africa'' as the fourth field:
$4 == "Asia" || $4 == "Africa"Another way to write the latter query is to use a regular expression with the alternation operator |:
$4 ~ /(Asia|Africa)/The negation operator ! has the highest precedence, then &&, and finally ||. The operators && and || evaluate their operands from left to right; evaluation stops as soon as truth or falsehood is determined.