Formatind and calculating output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatind and calculating output
# 1  
Old 04-18-2007
Formatind and calculating output

Hello every one,
I an new th shell script.
I am using this script to format output.

nawk -f nawk_a.sc doit1
and

HTML 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 advace
devmiral
# 2  
Old 04-18-2007
please look at the following output.
I get duplicate output and line keeps repeating after every output.
Please help what am i doing wrong. please look at the BOLD part they all r duplicate, for every line
Code:
    Mike Harrington:(510) 548-1278:250:100:175
Mike Harrington         (510) 548-1278  250.00  100.00  175.00  525.00
Christian Dobbins:(408) 538-2358:155:90:201
Christian Dobbins       (408) 538-2358  155.00  90.00   201.00  446.00
Susan Dalsass:(206) 654-6279:250:60:50
Susan Dalsass           (206) 654-6279  250.00  60.00   50.00   360.00
Archie McNichol:(206) 548-1348:250:100:175
Archie McNichol         (206) 548-1348  250.00  100.00  175.00  525.00
Jody Savage:(206) 548-1278:15:188:150
Jody Savage             (206) 548-1278  15.00   188.00  150.00  353.00
Guy Quigley:(916) 343-6410:250:100:175
Guy Quigley             (916) 343-6410  250.00  100.00  175.00  525.00
Dan Savage:(406) 298-7744:450:300:275
Dan Savage              (406) 298-7744  450.00  300.00  275.00  1025.00


Last edited by devmiral; 04-18-2007 at 02:20 PM.. Reason: Added output
devmiral
# 3  
Old 04-18-2007
Any help please
devmiral
# 4  
Old 04-18-2007
I got my solution
I have chaged my code as under
Code:
{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}
I changed code 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 braces.
by just making one it gives me correct output
devmiral
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grouping and Calculating

Hi All, I want to read the input file and store the output in the Output file. I pasted the sample Input and Output file below. Help me with this. Input file ================================= ITEM1 AAAAA 1 ITEM1 BBBBB 1 ITEM1 CCCCC 1 ITEM2 AAAAA 5 ITEM2 CCCCC 4... (1 Reply)
Discussion started by: humaemo
1 Replies

2. UNIX for Dummies Questions & Answers

Calculating average

Hi I have file like below 111,victor,48,12,36 342,Peter,54,58,30 476,Scott,25,36,48 567,Patty,74,17,95 I have written below code to calcualte avereage for every id Victor = 48+12+36/3 #!/bin/ksh /usr/xpg4/bin/awk ' BEGIN {FS=","} {sum=0; n=0;i=3 (1 Reply)
Discussion started by: stew
1 Replies

3. Shell Programming and Scripting

Calculating mean for samples 1-3 4-6 etc.

Hi. I have a LOOONG list of samples but I am not sure how to write the loop/script to calculate the mean... I normally use awk... ...................MEAN Sample1 25.82 40.61333 Sample1 47.6 Sample1 48.42 Sample2 54.03 54.12 Sample2 53.98 Sample2 54.35 etc..... I would like to... (4 Replies)
Discussion started by: danieladna
4 Replies

4. Shell Programming and Scripting

Calculating sum

Hi all, I have the following code in a shell script. Code: if then echo "##" echo "##" echo "##################################" for fn in `find "$1" -maxdepth 1 -iname \*"$2"* -type f` do echo "$fn" ... (2 Replies)
Discussion started by: naveendronavall
2 Replies

5. Shell Programming and Scripting

Calculating the epoch time from standard time using awk and calculating the duration

Hi All, I have the following time stamp data in 2 columns Date TimeStamp(also with milliseconds) 05/23/2012 08:30:11.250 05/23/2012 08:30:15.500 05/23/2012 08:31.15.500 . . etc From this data I need the following output. 0.00( row1-row1 in seconds) 04.25( row2-row1 in... (5 Replies)
Discussion started by: ks_reddy
5 Replies

6. Shell Programming and Scripting

Calculating using date

I need to help to calculating using date in a script. One application is licensed by date, some month at a time. I can read the date from system and get an output like this: echo $status 6A34 System4 01.01.11-31.01.11 My goal is to use license date 31.01.11 and subtract todays date... (7 Replies)
Discussion started by: Jotne
7 Replies

7. UNIX for Dummies Questions & Answers

Calculating average

Hi, i have 12 float variables in a bash file and i want to calculate the average of them. Can any body help? (6 Replies)
Discussion started by: limadario
6 Replies

8. Shell Programming and Scripting

calculating in MB

hi all, have got a ksh script which tries to monitor memory usage of app servers. i do a ps -0 rss -p <PID> to get the memory size in KB but when i divide by 1024 to convert to MB i dont know how to round it up ?? thanks in advance. (3 Replies)
Discussion started by: cesarNZ
3 Replies

9. Shell Programming and Scripting

calculating a number

Hello all :) I need some help; I'm running the sp_spaceused command on various tables and saving the output to a file. So, I have an input file that has 3 rows - each row has 7 columns. I would like to 1) sort the file on the 4th column, 2) take the 4th column in the first row and add 25% to... (2 Replies)
Discussion started by: stonemonolith
2 Replies

10. Shell Programming and Scripting

Calculating the average

This is the cronjob ---------------------- root@a7germ:/home/paxtemp > crontab -l|grep test 57 * * * * /home/paxtemp/test_1.sh 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /home/paxtemp/test.sh root@a7germ:/home/paxtemp > This is the contents of test.sh script... (2 Replies)
Discussion started by: kekanap
2 Replies
Login or Register to Ask a Question