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 Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
AWK Help (New to UNIX)

Write a script to calculate the average score and assign a letter grade for each student, also compute the average score for every test (the source data is in the file “grades”). Output all students’ name, scores, and grades in descending order of the average score. Note: please save the output to the file “finalgrades”.
Contents of source data file (grades):
Peter:90:80:70
Alice:79:89:69
David:99:79:89
The final letter grade will be determined based on the following criteria:
A: 90 and above; B: 80 thru 89; C: 70 thru 79; D: 60 thru 69; E; 50 thru 59; F: <50.
Output (finalgrades)



so far i have:

Code:
BEGIN{ print "Name   Test1   Test2   Test3   Average   Grade"}
{average=($2+$3+$4)/3;
grade="F"
if (average<50)
grade="E"
if (average<60)
grade="D"
if (average<70)
grade="C"
if (average<80)
grade="B"
if (average<90)
grade="A"
if (average<100)
printf("%-8s%-8d%-8d%-8d%-8d%-8d\n",$1,$2,$3,$4,average,grade)}

but grade is not working either

please help
  #2 (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,390
check your condition how can grade work here(logic is wrong)
if average is 40 then it satisfies all the condition
hmmm so make it as
Code:
if(average<50)
grade=E
if(average<60 && average>50)
grade=D
..
.
..
  #3 (permalink)  
Old 07-02-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Sounds like a homework question. Sounds like a homework answer, so that should play ;-)
  #4 (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,390
may be sounds like homework but he/she gave it a try but did some logical error so i corrected it thats it..
  #5 (permalink)  
Old 07-02-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
You make a good case.
  #6 (permalink)  
Old 07-02-2009
dsptl dsptl is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 9
OK thanks i have corrected my logical part but how do i print the last line?
  #7 (permalink)  
Old 07-02-2009
scottn scottn is online now Forum Advisor  
VIP Member
  
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,042
Pipe the output of awk through tail

Code:
... | tail -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 06:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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