Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GAWK problem with reading file

Status
Not open for further replies.

richardii

Programmer
Jan 8, 2001
104
GB
I've written a very simple gawk script that extracts error names and numbers from stored procedure *.bdy files. It works fine. However, we also have some errors in the *.spc files (Type = PKCS #7 Certificates). However I cannot make awk open these spc files. I get the message:

C:\API\GAWK.EXE: fatal error: cannot open file `c:\api\acc\src\gnvaccint.spc' for reading (No such file or directory)
source line number 4, file `errors.awk'

But the gnvaccint.spc *is* there. I can open it in the DOS editor. It just won't be opened for reading. The properties on the *.bdy and *.spc files is Read Only (I tried changing it - no effect).

Any help greatly appreciated. Thanks.
 
Post the existing script, please ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Here's the script. I can't really post an spc file as they're large, and guess it'd break some rule:

BEGIN{}


/[0-9][0-9][0-9][0-9][0-9]/&&/CONSTANT/{print ($0)}

 
Hi Richard.

Try this as I see you are running gawk and this will expedite your tshooting. See if it really is just some files that won't
open and others that will, then you'll know for certain.

function loader(fname, arr,x,longstr) {
while ((getline < fname) > 0) {
if ($0 ~ /[0-9][0-9][0-9][0-9][0-9]/ || $0 ~ /CONSTANT/) {
arr[x++] = $0
}
}
close(fname)

x = 0
for (x in arr) {
longstr = length(longstr) < 1 ? arr[x] &quot;\n&quot; : longstr&quot; &quot;arr[x] &quot;\n&quot;
}
return longstr
}

function parray(arr,x, p) {
while (p <= x) {
p++
print arr[p]
}
return
}


BEGIN {
qstr = &quot;NULL&quot;

while (qstr != &quot;quit&quot;) {
printf &quot;Name of file to open:(type: quit to end) &quot;
getline qstr < &quot;-&quot;
a = split(loader(qstr),loc,&quot;\n&quot;)
parray(loc,a)
}
}
 
Thanks for this. I found that the problem was related to running the awk script from a VB script, which was somehow &quot;holding onto&quot; the file, preventing gawk from accessing it. As soon as I used a DOS batch file it all worked fine. It wasn't just the *.spc files, it occurred regularly at points through out the processing of the files.
I guess the lesson must be don't use VB script to run file processing programs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top