Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Reading 5 Students names and grades using while loop????

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-26-2007
dlbomber1 dlbomber1 is offline
Registered User
 
Join Date: Nov 2007
Last Activity: 4 November 2008, 8:18 PM EST
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Reading 5 Students names and grades using while loop????

How do I write a shell script file to read 5 student names (First and Last name) and their grades using a While Loop? Find the Average, Maximum, and Minimum of grades using the same While Loop. Prompt the user using tput to enter the information (first name, last name, grade). Save the data in a file called students.txt. Sort the file by last name and display it on the screen. Someone gave me this to go buy but im way basic and am not sure if there is anything missing from this. I also need to be able to use Tput.
If anyone can help me get this done or tell me whats missing id appreciate it.

1. suppose file is of form "Name Surname Grade"

#!/bin/zsh

sum=0
min=10000
max=0
n=5
i=0
file="students.txt"

cat $file | while read line; do
set line
grade=$3
sum='expr $sum + $grade'
if [ $grade -gt $max ]; then
max=$grade
fi
if [ $grade -lt $min ]; then
min=$grade
fi
i='expr $i + 1'
if [ $i -ge $n ]; then
break
fi
done

average='expr $sum / $i'
echo "Max: $max Min: $min Avg: $average"
Sponsored Links
    #2  
Old Unix and Linux 11-26-2007
blowtorch's Unix or Linux Image
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 11 July 2015, 4:56 AM EDT
Location: UK
Posts: 2,351
Thanks: 0
Thanked 6 Times in 6 Posts
We have a pretty strict policy here about not allowing homework questions. I'm locking this thread.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with File Names under tcsh loop InfoSeeker Shell Programming and Scripting 4 10-22-2010 01:34 PM
File Names in a Variable in a loop spkandy Shell Programming and Scripting 3 06-11-2009 05:55 AM
help with a 'while read' loop to change the names of files starsky Shell Programming and Scripting 6 03-01-2008 12:47 PM
executing scripts by reading names from a file konark Shell Programming and Scripting 3 11-08-2007 01:28 AM



All times are GMT -4. The time now is 11:13 AM.