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

Pattern ranges

A pattern range consists of two patterns separated by a comma:

pattern1, pattern2 { ... }

In this case, the action is performed for each line between an occurrence of pattern1 and the next occurrence of pattern2 (inclusive). As an example, the pattern /Canada/, /Brazil/ matches lines starting with the first line that contains the string ``Canada'', up through the next occurrence of the string ``Brazil'':

   Canada       3852	24	North America
   China        3692	866	Asia
   USA          3615	219	North America
   Brazil       3286	116	South America
Similarly, because FNR is a built-in variable that represents the number of the current record in the current input file (and FILENAME is the name of the current input file), the following program prints the first five records of each input file with the name of the current input file prepended:
   FNR == 1, FNR == 5 { print FILENAME, $0 }

Next topic: Actions
Previous topic: Combining patterns

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