File existence checks in AWK
John Lacey
lacey at batcomputer.tn.cornell.edu
Fri Jul 7 04:14:01 AEST 1989
I am adapting/writing a simple database using AWK. The adapting
part is from the query processor qawk presented in ``The AWK Programming
Language'', by A, K, and W.
I am running on a Gould, and the version of AWK provided is the
early one; hence, it lacks functions, which qawk and I use. So,
I brought in GNU AWK (gawk) to handle that. Unfortunately, the
getline built-in is broken in gawk version 2.10. In particular,
getline <"file"
hangs instead of returning a -1, if "file" does not exist.
Determining whether a given file exists is crucial to my
application. Not so much for functionality as for running
speed. Now, I realize that if I wanted speed I shouldn't
have used AWK, but I think this is little enough to ask.
So, if anyone has a clean, simple way (or any way at all)
of determining in AWK without using getline (at least on
potentially non-existent files) whether a file exists,
I would love to hear from you.
The real hangup is that the system function doesn't return
the return value of the expression, but rather the status.
So, for example,
if (system("test -f " filename))
:
else
:
doesn't work.
--
John Lacey | Internet: lacey at tcgould.tn.cornell.edu
running unattached | BITnet: lacey at crnlthry
| UUCP: cornell!batcomputer!lacey
"Whereof one cannot speak, thereof one must remain silent." ---Wittgenstein
More information about the Comp.unix.questions
mailing list