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

Formating out put and calculating

Status
Not open for further replies.

miraora

Programmer
Jan 6, 2007
26
US
Hello I am new to Shell Scripting
SUN OS 5.9
I want out put in this format
Code:
                    ***CAMPAIGN 1998 CONTRIBUTIONS***

---------------------------------------------------------------------------

NAME                 PHONE             Jan  |  Feb  |  Mar |  Total Donated

---------------------------------------------------------------------------

Mike Harrington      (510) 548-1278  250.00   100.00  175.00  525.00

Christian Dobbins    (408) 538-2358  155.00    90.00  201.00  446.00

Susan Dalsass        (206) 654-6279  250.00    60.00   50.00  360.00

Archie McNichol      (206) 548-1348  250.00   100.00  175.00  525.00

Jody Savage          (206) 548-1278   15.00   188.00  150.00  353.00

Guy Quigley          (916) 343-6410  250.00   100.00  175.00  525.00

Dan Savage           (406) 298-7744  450.00   300.00  275.00  1025.00

Nancy McNeil         (206) 548-1278  250.00    80.00   75.00  405.00

John Goldenrod       (916) 348-4278  250.00   100.00  175.00  525.00

Chet Main            (510) 548-5258   50.00    95.00  135.00  280.00

Tom Savage           (408) 926-3456  250.00    68.00  200.00  618.00

Elizabeth Stachelin  (916) 440-1763  175.00    75.00  300.00  550.00

----------------------------------------------------------------------------

                               SUMMARY

----------------------------------------------------------------------------

The campaign received a total of $6137.00 for this quarter.

The average donation for the 12 contributors was $511.42.

The highest contribution was $300.00.

The lowest contribution was $15.00.
i am able to get output but not able to get
The highest contribution was $300.00.

The lowest contribution was $15.00.
and I am getting extra lines in the output, I don't know why.
can any one please help me.
Code:
                        ***CAMPAIGN 1998 CONTRIBUTIONS***

-------------------------------------------------------------------------------
Name                    PHONE           |  Jan  |  Feb  |  Mar | Total Donated
--------------------------------------------------------------------------------
                                0.00    0.00    0.00    0.00
Mike Harrington:(510) 548-1278:250:100:175
Mike Harrington         (510) 548-1278  250.00  100.00  175.00  525.00

                                0.00    0.00    0.00    0.00
Christian Dobbins:(408) 538-2358:155:90:201
Christian Dobbins       (408) 538-2358  155.00  90.00   201.00  446.00

                                0.00    0.00    0.00    0.00
Susan Dalsass:(206) 654-6279:250:60:50
Susan Dalsass           (206) 654-6279  250.00  60.00   50.00   360.00

                                0.00    0.00    0.00    0.00
Archie McNichol:(206) 548-1348:250:100:175
Archie McNichol         (206) 548-1348  250.00  100.00  175.00  525.00

                                0.00    0.00    0.00    0.00
Jody Savage:(206) 548-1278:15:188:150
Jody Savage             (206) 548-1278  15.00   188.00  150.00  353.00

                                0.00    0.00    0.00    0.00
Guy Quigley:(916) 343-6410:250:100:175
Guy Quigley             (916) 343-6410  250.00  100.00  175.00  525.00

                                0.00    0.00    0.00    0.00
Dan Savage:(406) 298-7744:450:300:275
Dan Savage              (406) 298-7744  450.00  300.00  275.00  1025.00

                                0.00    0.00    0.00    0.00
Nancy McNeil:(206) 548-1278:250:80:75
Nancy McNeil            (206) 548-1278  250.00  80.00   75.00   405.00

                                0.00    0.00    0.00    0.00
John Goldenrod:(916) 348-4278:250:100:175
John Goldenrod          (916) 348-4278  250.00  100.00  175.00  525.00

                                0.00    0.00    0.00    0.00
Chet Main:(510) 548-5258:50:95:135
Chet Main               (510) 548-5258  50.00   95.00   135.00  280.00

                                0.00    0.00    0.00    0.00
Tom Savage:(408) 926-3456:250:168:200
Tom Savage              (408) 926-3456  250.00  168.00  200.00  618.00

                             [b]   0.00    0.00    0.00    0.00
Elizabeth Stachelin:(916) 440-1763:175:75:300[/b]
Elizabeth Stachelin     (916) 440-1763  175.00  75.00   300.00  550.00

                                0.00    0.00    0.00    0.00
-------------------------------------------------------------------------------
                                 SUMMARY
-------------------------------------------------------------------------------
The total reveived for this quater is :$6137.00
The the avgerage total :$511.42
my fine contains as under
Code:
BEGIN{FS=":"
      printf "\n\t\t\t***CAMPAIGN 1998 CONTRIBUTIONS***\n\n"
      print "-------------------------------------------------------------------------------" 
      printf"Name\t\t\tPHONE\t\t|  Jan  |  Feb  |  Mar | Total Donated\n"
      print "--------------------------------------------------------------------------------" 
     }
     {tot=$3+$4+$5}
     qtr_tot=qtr_tot+tot
     {printf"%-20s\t%s\t%4.2f\t%4.2f\t%3.2f\t%3.2f\n",$1,$2,$3,$4,$5,tot}
      
       
     
  END{print "-------------------------------------------------------------------------------" 
      print"\t\t\t\t SUMMARY"
      print "-------------------------------------------------------------------------------"       
      {printf"The total reveived for this quater is :$%6.2f\n",qtr_tot}
      {printf"The the avgerage total :$%6.2f\n",qtr_tot/12}
     }

Thank you in advance
 
how do you start this script? Where is the info stored eg "John Goldenrod:(916) 348-4278:250:100:175"

Best Regards, Franz
--
System Manager (Solaris, HP-UX, Linux, some networking, some SAN)
 
Hello
Thank you for your reply.
I run this at prompt like this
nawk -f nawk_a.sc doit1
I keep getting extra line, I don't know why.
Thank you for your help once again
 
Thank you I go the solution,
Code:
{tot=$3+$4+$5<b>}</b>
     qtr_tot=qtr_tot+tot
     <b>{</b>printf"%-20s\t%s\t%4.2f\t%4.2f\t%3.2f\t%3.2f\n",$1,$2,$3,$4,$5,tot}
I chaged to 
{tot=$3+$4+$5
     qtr_tot=qtr_tot+tot
     printf"%-20s\t%s\t%4.2f\t%4.2f\t%3.2f\t%3.2f\n",$1,$2,$3,$4,$5,tot}

Please can you tell me why we need one curly barces.
by just making one it gives me correct output

 
sorry, I am not an {n,}awk expert (I usually use it as a flexibel 'cut' sub), I cannot tell you why. If you need to know more about this I suggest to ask in an awk forum...

Best Regards, Franz
--
System Manager (Solaris, HP-UX, Linux, some networking, some SAN)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top