DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Using awk

Combining patterns

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 > 500
This 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.

Next topic: Pattern ranges
Previous topic: awk regular expressions

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003