|
|
A compound pattern combines simpler patterns with parentheses and the logical operators || (or), && (and), and ! (not). For example, suppose you want to print all countries in Asia with a population of more than 500 million. The following program does this by selecting all lines in which the fourth field is Asia and the third field exceeds 500:
$4 == "Asia" && $3 > 500The program
$4 == "Asia" || $4 == "Africa"selects lines with Asia or Africa as the fourth field. Another way to write the latter query is to use an extended 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.