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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want to display the consolidated count? how to do it?

Status
Not open for further replies.

CALYAN

Programmer
Apr 23, 2001
39
0
0
US
I am having the report like this
Reg code Cntry code Count
-------- ---------- ------
AF AO 177
AF BF 56
AF BI 8
AF BJ 78
AF BW 282
AF CD 323
AF CF 53
AF CG 136
AF CI 410
AF CM 292
AF CV 8
AF DJ 9
AF ER 15

but i want to display along with grand total

Reg code Cntry code Count
-------- ---------- ------
AF AO 177
AF BF 56
AF BI 8
AF BJ 78
AF BW 282
AF CD 323
AF CF 53
AF CG 136
AF CI 410

-----------
Grand total
-----------

How to do it?
rgds
calyan
 
My poor awk solution:

/Reg code/{
print $0
next
}
/\--*/{
print $0
next
}
{
sum += $3
print
}
END{
printf "%34s\n", "-------"
printf "%25s %8d\n", "Grand total", sum
printf "%34s\n", "-------"
}

tikual
 
or you can try this with awk:

{print $0;
if($1=="AF")sum+=$3;
}
END{
print "Grand Total = " sum
}
 
Better still, if the reg.code (AF) is expected to change, the following will still work as long as the last line of the heading begins with at least three hyphens:

{print $0;
if(OK)sum+=$3;
if($1~"---*")OK=1;
}
END{
print "Grand Total = " sum
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top