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

Pattern ranges

A pattern range consists of two patterns separated by a comma, as in

   pat[1], pat[2]     { . . . }
In this case, the action is performed for each line between an occurrence of pat[1] and the next occurrence of pat[2] (inclusive). For 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, since FNR is the number of the current record in the current input file (and FILENAME is the name of the current input file), the program

   FNR == 1, FNR == 5 { print FILENAME, $0 }
prints the first five records of each input file with the name of the current input file prepended.
Next topic: Actions
Previous topic: Combinations of patterns

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005