Not able to get to the total for the last line. Please help
{
if(substr($0,1,1)=="H") {
# do this
#remove first Character
sub( /./, "" )
#read header
fh1 = substr($0,1,7)
fh2 = substr($0,8,7)
fh3 = substr($0,15,8)
fh4 = substr($0,23,8)
fh4a = substr($0,32,7)
fh4b = substr($0,39,7)
fh4c = substr($0,46,7)
#fh5 = substr($0,69,11)
fh6 = substr($0,60,6)
fh6a = substr($0,69,11)
fh7 = substr($0,103,12)
# total line (after each group of data line)
printf ("%-1s,%-2s,%-3s,%-4s,%-5s, %51.2f ,%7.2f \n","","","","",qty, tfd6/100,tfd7/100) > "INVOICE.xls"
printf "\n\n\n" > "INVOICE.xls"
printf ("Dealer_code,%-7s, \n", fh1) > "INVOICE.xls"
printf ("INV#,%-7s \n", fh2) > "INVOICE.xls"
printf ("date, %-8s \n", fh3 ) > "INVOICE.xls"
printf ("ETDdate,%-8s \n", fh4) > "INVOICE.xls"
printf ("G-Weight,%-8s \n", fh4a/100) > "INVOICE.xls"
printf ("N-Weight,%-8s \n", fh4b/100) > "INVOICE.xls"
printf ("Meas,%-8s \n", fh4c/100) > "INVOICE.xls"
printf ("FRGCHG,%8.2f \n",fh6a/100 ) > "INVOICE.xls"
printf ("T_order:,%8.2f \n",fh6/100) > "INVOICE.xls"
gtfh56 = fh6a + fh6
printf ("Grand_total:,%8.2f \n",gtfh56/100) > "INVOICE.xls"
printf ("Conatiner_no., %-12s \n", fh7) > "INVOICE.xls"
printf "\n" > "INVOICE.xls"
printf ("%-10s,%-10s, %-4s, %-12s, %-4s, %-8s, %-7s \n", "Case_NO."," Order_NO."," L/N"," Part_no."," Qty."," Unit Price"," Amount") > "INVOICE.xls"
tfd6 = 0
tfd7 = 0
qty = 0
# read DATA record
} else if(substr($0,1,1)=="D") {
# Removed first character
sub( /./, "" )
fd1 = substr($0,1,8)
fd2 = substr($0,9,7)
fd3 = substr($0,18,3)
fd4 = substr($0,21,12)
# Insert "-" after each group of 5 chars.
gsub( /...../, "&-", fd4 )
# Remove any trailing "-".
sub( /- *$/, "", fd4 )
fd5 = substr($0,37,5)
fd6 = substr($0,43,9)
fd7 = substr($0,53,14)
tfd6 = tfd6 + fd6
tfd7 = tfd7 + fd7
qty = qty + fd5
printf ("%-7s,%-7s,%-4s,%-15s,%-5s,%8.2f,%8.2f \n",fd1,fd2,fd3,fd4,fd5,fd6/100,fd7/100 ) > "INVOICE.xls"
}
}
[/qoute]