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 "RXOTRX-" substr(a[j],7) > fn
split(a[0], arr, "-"
b=arr[2];
print "RXOCON-" b > fn
print "RXODP-" b > fn
print "RXOIS-" b > fn
print "RXOTF-" b > fn
print "RXOCF-" b > fn
print "RXOTG-" b > fn
close(fn)
}
num = n2 = 0
fnix++
fn = "block_obj_" 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 "RXOTRX-" substr(a[j],7) > fn
split(a[0], arr, "-"
b=arr[2];
print "RXOCON-" b > fn
print "RXODP-" b > fn
print "RXOIS-" b > fn
print "RXOTF-" b > fn
print "RXOCF-" b > fn
print "RXOTG-" b > fn
}
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 "RXOTRX-" substr(a[j],7) > fn
split(a[0], arr, "-"
b=arr[2];
print "RXOCON-" b > fn
print "RXODP-" b > fn
print "RXOIS-" b > fn
print "RXOTF-" b > fn
print "RXOCF-" b > fn
print "RXOTG-" b > fn
close(fn)
}
num = n2 = 0
fnix++
fn = "block_obj_" 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 "RXOTRX-" substr(a[j],7) > fn
split(a[0], arr, "-"
b=arr[2];
print "RXOCON-" b > fn
print "RXODP-" b > fn
print "RXOIS-" b > fn
print "RXOTF-" b > fn
print "RXOCF-" b > fn
print "RXOTG-" b > fn
}