There's a few problems with this script.

1) Setting %f to $$1 will not take into account files that have spaces in the name. Use $$1- instead.

2) $lines%f should be $lines(%f)

3) Calling $read without the 'n' flag will evaluate identifiers in the file.

Also, that loop could be greatly sped up by setting $lines(%f) to a variable instead of calling it in each iteration of the loop:

Code:
var %x = 1, %f = $$1-, %l = $lines(%f)
while (%x <= %l) {
...
}