The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to make a loop base on reading a file? JohnBalayo UNIX for Dummies Questions & Answers 3 04-02-2008 03:36 AM
How to make a loop base on reading a file? JohnBalayo HP-UX 3 04-01-2008 08:58 PM
help with a 'while read' loop to change the names of files starsky Shell Programming and Scripting 6 03-01-2008 09:47 AM
executing scripts by reading names from a file konark Shell Programming and Scripting 3 11-07-2007 10:28 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-25-2007
Registered User
 

Join Date: Nov 2007
Posts: 1
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"
Forum Sponsor
  #2 (permalink)  
Old 11-25-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,325
We have a pretty strict policy here about not allowing homework questions. I'm locking this thread.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0