The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #8 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
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
  #9 (permalink)  
Old 07-02-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
your logic is again wrong what if average is comes out as 75.
it will be true in last three if statements..
and that 0 is coming because you used %d in printf to print grade use %s
  #10 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
Quote:
Originally Posted by vidyadhar85 View Post
your logic is again wrong what if average is comes out as 75.
it will be true in last three if statements..
and that 0 is coming because you used %d in printf to print grade use %s
ok thanks i just had to change d to s

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....
  #11 (permalink)  
Old 07-02-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
This is what you looking for..
Code:
BEGIN{ print "Name   Test1   Test2   Test3   Average   Grade"}
{avg=($2+$3+$4)/3;
                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{
print "Average"}
  #12 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
Quote:
Originally Posted by vidyadhar85 View Post
This is what you looking for..
Code:
BEGIN{ print "Name   Test1   Test2   Test3   Average   Grade"}
{avg=($2+$3+$4)/3;
                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{
print "Average"}
no i hv this

i am looking for the last line in output which is average of each test

here:

  #13 (permalink)  
Old 07-02-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
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}
  #14 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
it prints 0 for test 1
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0