![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Enterprise Unix Roundup: The Ghost of Unix Future - Server Watch | iBot | UNIX and Linux RSS News | 0 | 12-19-2007 12:20 PM |
| Running UNIX commands remotely in Windows box from Unix box – avoid entering password | D.kalpana | UNIX for Dummies Questions & Answers | 1 | 04-20-2007 05:24 AM |
| FTP script for sending a file from one unix directory to another unix server director | raja_1234 | Shell Programming and Scripting | 1 | 11-30-2006 07:57 AM |
| Unix History Question: Why are filenames/dirnames case sentsitive in Unix? | deckard | UNIX for Dummies Questions & Answers | 3 | 03-26-2005 01:59 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
still cant figure it out.....please help
Code:
BEGIN{ print "Name Test1 Test2 Test3 Average Grade"}
{avg=($2+$3+$4)/3;
if (avg >= 90) grade="A"
else if (avg >= 80) grade="B"
else if (avg >= 70) grade="C"
else if (avg >= 60) grade="D"
else grade="F"
printf("%-8s%-8d%-8d%-8d%-8d%-8d\n",$1,$2,$3,$4,avg,grade)}
END{
print "Average"}
I am getting this as my output after i do $ awk -F: -fp.awk grade Code:
Name Test1 Test2 Test3 Average Grade Peter 90 80 70 80 0 Alive 79 89 69 79 0 David 99 79 89 89 0 Average |
|
||||
|
Quote:
but still the last part average, how do i take average of test 1, test 2, and test 3? I know how to do individual's average but dont know how to do average from a column like test 1 grades.... |
|
||||
|
Quote:
i am looking for the last line in output which is average of each test here: |
|
|||||
|
Is it ok now??
Code:
BEGIN{ print "Name Test1 Test2 Test3 Average Grade"}
{avg=($2+$3+$4)/3;avgtest1+=$2
avgtest2+=$3
avgtest3+=$4
if (avg >= 90 && avg < 100) grade="A"
else if (avg >= 80 && avg < 89) grade="B"
else if (avg >= 70 && avg < 79) grade="C"
else if (avg >= 60 && avg <69) grade="D"
else grade="F"
printf("%-8s%-8d%-8d%-8d%-8d%-8s\n",$1,$2,$3,$4,avg,grade)}
END{
printf "Average%-8d%-8d%-8d\n",avgtest1/NR,avgtest2/NR,avgtest3/NR}
|
|
||||
|
it prints 0 for test 1
|
| Sponsored Links | ||
|
|