(gawk.info.gz) Rewind Function
Info Catalog
(gawk.info.gz) Filetrans Function
(gawk.info.gz) Data File Management
(gawk.info.gz) File Checking
12.3.2 Rereading the Current File
---------------------------------
Another request for a new built-in function was for a `rewind()'
function that would make it possible to reread the current file. The
requesting user didn't want to have to use `getline' ( Getline)
inside a loop.
However, as long as you are not in the `END' rule, it is quite easy
to arrange to immediately close the current input file and then start
over with it from the top. For lack of a better name, we'll call it
`rewind()':
# rewind.awk --- rewind the current file and start over
function rewind( i)
{
# shift remaining arguments up
for (i = ARGC; i > ARGIND; i--)
ARGV[i] = ARGV[i-1]
# make sure gawk knows to keep going
ARGC++
# make current file next to get done
ARGV[ARGIND+1] = FILENAME
# do it
nextfile
}
This code relies on the `ARGIND' variable ( Auto-set), which
is specific to `gawk'. If you are not using `gawk', you can use ideas
presented in Filetrans Function, to either update `ARGIND' on
your own or modify this code as appropriate.
The `rewind()' function also relies on the `nextfile' keyword (
Nextfile Statement).
Info Catalog
(gawk.info.gz) Filetrans Function
(gawk.info.gz) Data File Management
(gawk.info.gz) File Checking
automatically generated by
info2html