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!

Missing Close Statement 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
Here is another file where the close statement is missing, I tried to add it at the bottom, but it did not work.

#---------Nawk12--------------
{
if (FNR==1) {
for (j=1;j<=11;j++) a[j] = 0
fn1 = FILENAME
sub(/[^0-9]*/,&quot;&quot;,fn1)
fn2 = &quot;pre_build_e&quot; fn1
fn1 = &quot;antennas_power_&quot; fn1
print fn1
while ((getline s < fn1) > 0) {
print s
if (s ~ &quot;RXOTX&quot;) {
split(s,f1)
split(f1[1],n1,&quot;-&quot;)
a[n1[3]] = f1[6]
}
}
}
if ($0 ~ &quot;RXOTX&quot;) {
split($0,f1,&quot;,&quot;)
j = split(f1[1],n1,&quot;-&quot;)
print j &quot; &quot; n1[1] &quot; &quot; n1[3] &quot; &quot; a[n1[3]]
if (a[n1[3]]) sub(/POWER/,a[n1[3]])
}
print > fn2
}
 

if (FNR==1) {
if (fn1) close(fn1)
if (fn2) close(fn2)
for (j=1;j<=11;j++) a[j] = 0
CaKiwi
 
CaKiwi,
Every answer you have provided has worked perfect! I can't wait until the cleanup on all of these is done. I have 5 more still left to go through, the only question I have is really is where to put the close statements. I am almost dead on now where and how to create files with the same name.....thanks to you guys!

Where should the close statement go in this one?

#----nawk17----
BEGIN {
FileROOT=&quot;pre_build_i&quot;
unknownNUM=&quot;999999&quot;;
}

FNR == 1 {
if (match(FILENAME, &quot;[0-9]&quot;)) {
n = substr(FILENAME, RSTART, RLENGTH)
output=FileROOT n
}
else
output=outputFileROOT unknownNUM
flg = 0
fn = &quot;dcp_test_&quot; n
print fn
while ((getline a < fn) > 0) {
split(a,b)
print b[1] &quot; , &quot; b[2] &quot; , &quot; b[3]
if (!flg) {
n1 = b[2]
flg = 1
}
n2 = b[2]
}
print n1 &quot; , &quot; n2
}

{
gsub(/FIRST_DCP/, n1, $0)
gsub(/SECOND_DCP/, n2, $0)
#print
print > output
}
 
FNR == 1 {
if (output) close(output)
if (fn) close(fn)
if (match(FILENAME, &quot;[0-9]&quot;)) { CaKiwi
 
That worked out fine! I had to add:

if (match(FILENAME, &quot;[0-9]+&quot;))

To get it to process more than 9 output files.
 
I'd say CaKiwi should get a star for 'perserverance' [wink] vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Thanks vlad! beaster's promises that the end is in sight have given me a new burst of energy, I'm running on pure adrenaline now :) CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top