| echo T.nextfile: tests of nextfile command |
| |
| awk=${awk-../a.out} |
| |
| # 1st lines of some files |
| rm -f foo0 |
| for i in T.* |
| do |
| sed 1q $i >>foo0 |
| done |
| |
| $awk ' |
| { print $0; nextfile } # print first line, quit |
| ' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 1' |
| |
| $awk ' # same test but in a for loop |
| { print $0; |
| for (i = 1; i < 10; i++) |
| if (i == 1) |
| nextfile |
| print "nextfile for error" |
| } # print first line, quit |
| ' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 1f' |
| |
| $awk ' # same test but in a while loop |
| { print $0; |
| i = 1 |
| while (i < 10) |
| if (i++ == 1) |
| nextfile |
| print "nextfile while error" |
| } # print first line, quit |
| ' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 1w' |
| |
| $awk ' # same test but in a do loop |
| { print $0; |
| i = 1 |
| do { |
| if (i++ == 1) |
| nextfile # print first line, quit |
| } while (i < 10) |
| print "nextfile do error" |
| } |
| ' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 1d' |
| |
| |
| # 100 lines of some files |
| rm -f foo0 |
| for i in T.* |
| do |
| sed 100q $i >>foo0 |
| done |
| |
| $awk ' |
| { print } |
| FNR == 100 { nextfile } # print first line, quit |
| ' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 2' |
| |
| |
| >foo0 # empty |
| $awk ' { nextfile; print $0 }' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 3' |
| |
| # skip weird args |
| rm -f foo0 |
| for i in T.* |
| do |
| sed 1q $i >>foo0 |
| done |
| |
| $awk ' |
| { print $0; nextfile } # print first line, quit |
| ' T.* >foo1 |
| |
| diff foo0 foo1 || echo 'BAD: T.nextfile 4' |