Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
with this data
Mike Harrington:(510) 548-1278:250:100:175
Christian Dobbins:(408) 538-2358:155:90:201
Susan Dalsass:(206) 654-6279:250:60:50
Archie McNichol:(206) 548-1348:250:100:175
Jody Savage:(206) 548-1278:15:188:150
Guy Quigley:(916) 343-6410:250:100:175
Dan Savage:(406) 298-7744:450:300:275
Nancy McNeil:(206) 548-1278:250:80:75
John Goldenrod:(916) 348-4278:250:100:175
Chet Main:(510) 548-5258:50:95:135
Tom Savage:(408) 926-3456:250:168:200
Elizabeth Stachelin:(916) 440-1763:175:75:300
And this is my script....what am i doing wrong?
BEGIN{FS=":"
print "\t\t\t***CAMPAIGN 1998 CONTRIBUTIONS***"
print "---------------------------------------------------------"
print "NAME\t\t\tPHONE\t\t\tPHONE\t\t\tJan | Feb | Mar | Total Donation"
print "---------------------------------------------------------\n"
}
{total+=$3$4$5}
{average=total/12}
{print $1\t\t$2\t\t\t$3, $4, $5, total}
END{print "------------------------------------------------------------\n"
print "\t\t\t\tSUMMARY"
print "---------------------------------------------------------\n"
}
{print "The campaign received a total of $" total " for this quarter."}
{print "The average donation for the 12 contributors was" average "."}
something is wrong with this message box thingy but the outcome is suppose to be in order. The data is suppose to be under the proper categories
Last edited by JoeRogan; 11-25-2011 at 02:00 PM.
Reason: not what i ment to type
Click here to see the post LQ members have rated as the most helpful post in this thread.
How about you tell us what you see, explain how it doesn't match what you
expect, and then we'll discuss where you went wrong ...
To get the thought process started: the first thing I see is that the TABs
on line 9 aren't in quotes, so you're going to have a syntax error there
to begin with.
***CAMPAIGN 1998 CONTRIBUTIONS***
---------------------------------------------------------
NAME PHONE PHONE Jan | Feb | Mar | Total Donation
---------------------------------------------------------
Mike Harrington (510) 548-1278 250 100 175 250100175
The campaign received a total of $250100175 for this quarter.
The average donation for the 12 contributors was2.08417e+07.
250100175
The campaign received a total of $250100175 for this quarter.
The average donation for the 12 contributors was2.08417e+07.
Christian Dobbins (408) 538-2358 155 90 201 265690376
The campaign received a total of $265690376 for this quarter.
The average donation for the 12 contributors was2.21409e+07.
265690376
The campaign received a total of $265690376 for this quarter.
The average donation for the 12 contributors was2.21409e+07.
Susan Dalsass (206) 654-6279 250 60 50 268196426
The campaign received a total of $268196426 for this quarter.
The average donation for the 12 contributors was2.23497e+07.
268196426
The campaign received a total of $268196426 for this quarter.
The average donation for the 12 contributors was2.23497e+07.
Archie McNichol (206) 548-1348 250 100 175 518296601
The campaign received a total of $518296601 for this quarter.
The average donation for the 12 contributors was4.31914e+07.
518296601
The campaign received a total of $518296601 for this quarter.
The average donation for the 12 contributors was4.31914e+07.
Jody Savage (206) 548-1278 15 188 150 533484751
The campaign received a total of $533484751 for this quarter.
The average donation for the 12 contributors was4.44571e+07.
533484751
The campaign received a total of $533484751 for this quarter.
The average donation for the 12 contributors was4.44571e+07.
Guy Quigley (916) 343-6410 250 100 175 783584926
The campaign received a total of $783584926 for this quarter.
The average donation for the 12 contributors was6.52987e+07.
783584926
The campaign received a total of $783584926 for this quarter.
The average donation for the 12 contributors was6.52987e+07.
Dan Savage (406) 298-7744 450 300 275 1233885201
The campaign received a total of $1233885201 for this quarter.
The average donation for the 12 contributors was1.02824e+08.
1233885201
The campaign received a total of $1233885201 for this quarter.
The average donation for the 12 contributors was1.02824e+08.
Nancy McNeil (206) 548-1278 250 80 75 1236393276
The campaign received a total of $1236393276 for this quarter.
The average donation for the 12 contributors was103032773.
1236393276
The campaign received a total of $1236393276 for this quarter.
The average donation for the 12 contributors was103032773.
John Goldenrod (916) 348-4278 250 100 175 1486493451
The campaign received a total of $1486493451 for this quarter.
The average donation for the 12 contributors was1.23874e+08.
1486493451
The campaign received a total of $1486493451 for this quarter.
The average donation for the 12 contributors was1.23874e+08.
Chet Main (510) 548-5258 50 95 135 1491588586
The campaign received a total of $1491588586 for this quarter.
The average donation for the 12 contributors was1.24299e+08.
1491588586
The campaign received a total of $1491588586 for this quarter.
The average donation for the 12 contributors was1.24299e+08.
Tom Savage (408) 926-3456 250 168 200 1741756786
The campaign received a total of $1741756786 for this quarter.
The average donation for the 12 contributors was1.45146e+08.
1741756786
The campaign received a total of $1741756786 for this quarter.
The average donation for the 12 contributors was1.45146e+08.
Elizabeth Stachelin (916) 440-1763 175 75 300 1759332086
The campaign received a total of $1759332086 for this quarter.
The average donation for the 12 contributors was1.46611e+08.
------------------------------------------------------------
BTW way guys im using Unix Shell By Examples Fourth Edition By ELLIE QUIGLEY to help me started with scripting and this book is confusing and too advanced for me..what do u guys suggest for a beginner? almost 60-70 % of the time im googling things to understand what they are saying..I need something VERY basic. PLZ and thx
Grail i fixed that issue. the problem now im having is how do i write a script for getting the total amount from the "Total Donated" section..i want to add all the data from that section and write a sentence that says.."The campaign received a total of $_____ for this quarter."
oden$ awk -f dad gangster
***CAMPAIGN 1998 CONTRIBUTIONS***
---------------------------------------------------------
NAME PHONE Jan | Feb | Mar | Total Donation
---------------------------------------------------------
Mike Harrington (510) 548-1278 250 100 175 525
0
Christian Dobbins (408) 538-2358 155 90 201 446
0
Susan Dalsass (206) 654-6279 250 60 50 360
0
Archie McNichol (206) 548-1348 250 100 175 525
0
Jody Savage (206) 548-1278 15 188 150 353
0
Guy Quigley (916) 343-6410 250 100 175 525
0
Dan Savage (406) 298-7744 450 300 275 1025
0
Nancy McNeil (206) 548-1278 250 80 75 405
0
John Goldenrod (916) 348-4278 250 100 175 525
0
Chet Main (510) 548-5258 50 95 135 280
0
Tom Savage (408) 926-3456 250 168 200 618
0
Elizabeth Stachelin (916) 440-1763 175 75 300 550
------------------------------------------------------------
The campaign received a total of $6137 for this quarter.
The average donation for the 12 contributors was511.417.
I am getting very close.. i am using this script
print "\t\t\t***CAMPAIGN 1998 CONTRIBUTIONS***"
print "---------------------------------------------------------"
print "NAME\t\t\tPHONE\t\t\tJan | Feb | Mar | Total Donation"
print "---------------------------------------------------------\n"
}
{line_total=$3+$4+$5}
{total+=line_total}
{average=total/12}
{print $1"\t\t"$2"\t\t\t"$3, $4, $5, line_total}
END{print "------------------------------------------------------------\n"
print "\t\t\t\tSUMMARY"
print "---------------------------------------------------------\n"
print "The campaign received a total of $" total " for this quarter."
print "The average donation for the 12 contributors was" average "."}
Only a few issues..the datas are not alligning properly and how do i write a script where i divide the total quarterly by 12.
The only issue with calculating the average that I can see is that you are "hard coding" the number of donations to 12. It would be better to count the number of donations from the input file rather than specifying it.
I also have a slight issue with the input file, I would suggest removing the blank lines (although this could be coded for)
Have you looked at the reference provided by grail? This covers a lot more than print formating, check out regexp for removing blank lines from your input. and check out "Increment Ops" for a simple counter.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.