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!

Using same file# in pre-existing script

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I have the below script that I run like:

nawk -f nawk4 file*

You will see below that it creates output files called block_obj_#

The problem is, it isn't naming the output file with the exact same number as the input file. So input file8 would generate an output file of block_obj_8

Can someone help me fix the script?

#----nawk4----
{
if (FNR == 1) {
if (NR>1) {
for(j=0;j<num;j++) print &quot;RXOTRX-&quot; substr(a[j],7) > fn
split(a[0], arr, &quot;-&quot;);
b=arr[2];
print &quot;RXOCON-&quot; b > fn
print &quot;RXODP-&quot; b > fn
print &quot;RXOIS-&quot; b > fn
print &quot;RXOTF-&quot; b > fn
print &quot;RXOCF-&quot; b > fn
print &quot;RXOTG-&quot; b > fn
close(fn)
}
num = n2 = 0
fnix++
fn = &quot;block_obj_&quot; fnix
}
if ($1 ~ /^RXOTS/) {print $1 > fn}
if ($1 ~ /^RXORX/) {a2[n2++] = $1}
if ($1 ~ /^RXOTX/) {
for (j=0;j<n2;j++) print a2[j] > fn
n2 = 0
a[num] = $1; num++; print $1 > fn
}
}
END {
for(j=0;j<num;j++) print &quot;RXOTRX-&quot; substr(a[j],7) > fn
split(a[0], arr, &quot;-&quot;);
b=arr[2];
print &quot;RXOCON-&quot; b > fn
print &quot;RXODP-&quot; b > fn
print &quot;RXOIS-&quot; b > fn
print &quot;RXOTF-&quot; b > fn
print &quot;RXOCF-&quot; b > fn
print &quot;RXOTG-&quot; b > fn
}
 
This is untested, but try replacing

fnix++
fn = &quot;block_obj_&quot; fnix

with

fn = FILENAME
sub(/^[^0-9]*/,&quot;&quot;,fn)
fn = &quot;block_obj_&quot; fn
CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top