ref: 0e21daeb990191793cea556ab63fd68e7b3b48ec
dir: /test/T.nextfile/
#!/bin/rc
echo T.nextfile: tests of nextfile command
# 1st lines of some files
rm -f foo0
for(i in T.*)
sed 1q $i >>foo0
$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.*)
sed 100q $i >>foo0
$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.*)
sed 1q $i >>foo0
$awk '
{ print $0; nextfile } # print first line, quit
' T.* >foo1
diff foo0 foo1 || echo 'BAD: T.nextfile 4'