github.com/benhoyt/goawk@v1.8.1/testdata/T.nextfile (about)

     1  echo T.nextfile: tests of nextfile command
     2  
     3  awk=${awk-../a.out}
     4  
     5  # 1st lines of some files
     6  rm -f foo0
     7  for i in T.*
     8  do
     9  	sed 1q $i >>foo0
    10  done
    11  
    12  $awk '
    13  { print $0; nextfile }	# print first line, quit
    14  ' T.* >foo1
    15  
    16  diff foo0 foo1 || echo 'BAD: T.nextfile 1'
    17  
    18  $awk '	# same test but in a for loop
    19  { print $0; 
    20    for (i = 1; i < 10; i++)
    21  	if (i == 1)
    22  		nextfile
    23    print "nextfile for error"
    24  }	# print first line, quit
    25  ' T.* >foo1
    26  
    27  diff foo0 foo1 || echo 'BAD: T.nextfile 1f'
    28  
    29  $awk '	# same test but in a while loop
    30  { print $0; 
    31    i = 1
    32    while (i < 10)
    33  	if (i++ == 1)
    34  		nextfile
    35    print "nextfile while error"
    36  }	# print first line, quit
    37  ' T.* >foo1
    38  
    39  diff foo0 foo1 || echo 'BAD: T.nextfile 1w'
    40  
    41  $awk '	# same test but in a do loop
    42  { print $0; 
    43    i = 1
    44    do {
    45  	if (i++ == 1)
    46  		nextfile	# print first line, quit
    47    } while (i < 10)
    48    print "nextfile do error"
    49  }
    50  ' T.* >foo1
    51  
    52  diff foo0 foo1 || echo 'BAD: T.nextfile 1d'
    53  
    54  
    55  # 100 lines of some files
    56  rm -f foo0
    57  for i in T.*
    58  do
    59  	sed 100q $i >>foo0
    60  done
    61  
    62  $awk '
    63  { print }
    64  FNR == 100 { nextfile }	# print first line, quit
    65  ' T.* >foo1
    66  
    67  diff foo0 foo1 || echo 'BAD: T.nextfile 2'
    68  
    69  
    70  >foo0	# empty
    71  $awk ' { nextfile; print $0 }' T.* >foo1
    72  
    73  diff foo0 foo1 || echo 'BAD: T.nextfile 3'
    74  
    75  # skip weird args
    76  rm -f foo0
    77  for i in T.*
    78  do
    79  	sed 1q $i >>foo0
    80  done
    81  
    82  $awk '
    83  { print $0; nextfile }	# print first line, quit
    84  ' T.* >foo1
    85  
    86  diff foo0 foo1 || echo 'BAD: T.nextfile 4'