Sponsored Content
Top Forums Shell Programming and Scripting Reading 5 Students names and grades using while loop???? Post 302147201 by dlbomber1 on Monday 26th of November 2007 12:34:51 AM
Old 11-26-2007
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"
 

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

executing scripts by reading names from a file

file.txt contains ------------------ sat1 1300 sat2 2400 sat3 sat4 500 I need to write a shell script that will output like the below #output sat1.ksh 1300 sat2.ksh 2400 sat3.ksh sat4.ksh 500 my try ------- #!/bin/ksh for i in `cat file.txt` (3 Replies)
Discussion started by: konark
3 Replies

2. Shell Programming and Scripting

help with a 'while read' loop to change the names of files

Hi, I am new to scripting, so any help on this would be much appreciated. I am trying to rename a bunch of files, taking the names sequentially from a list read in another file... # ls oldnames file_1 file_2 file_3 # cat names red yellow green I want the files to take on the... (6 Replies)
Discussion started by: starsky
6 Replies

3. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

4. Shell Programming and Scripting

Problem with File Names under tcsh loop

Hello, I have a question regarding file naming under a loop in tcsh. I have the following code: #!/bin/tcsh foreach file (test/ProteinDirectory/*) # The * is a bunch of ProteinFile1, ProteinFile2, ProteinFile3, etc. sh /bioinfo/home/dgendoo/THREADER/pGenThreader.sh $file $file ... (4 Replies)
Discussion started by: InfoSeeker
4 Replies

5. UNIX for Dummies Questions & Answers

Loop through directory names

Some guidance is highly appreciated. I have 10 directories with names ending with 'xyz', each of them have about 30000 files. I want to loop through the contents of each directory and produce a single output per directory. So I want to have 10 output files named 'directory_name'_out. With... (1 Reply)
Discussion started by: newbie83
1 Replies

6. Shell Programming and Scripting

Print file names in a loop

OS : RHEL 6.1 Shell : Bash I have lots of files in /tmp/stage directory as show below. Using a loop, I need to print all the filenames in this directory except those ending with a number. How can I do this ? # pwd /tmp/stage # # # ls -l * -rw-r--r--. 1 root root 0 Oct 7 18:38 stmt1... (2 Replies)
Discussion started by: kraljic
2 Replies

7. Homework & Coursework Questions

Grades exercise

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell script program that will input a name and a mark between 0 and 100. The program then displays the... (9 Replies)
Discussion started by: UniverseCloud
9 Replies
RPL(1)							    BSD General Commands Manual 						    RPL(1)

NAME
rpl -- replace strings in files SYNOPSIS
rpl [-LhiwbqvsRepfdt] [-xSUFFIX] <old_string> <new_string> <target_file ...> DESCRIPTION
Basic usage is to specify two strings and one or more filenames or directories on the command line. The first string is the string to replace, and the second string is the replacement string. -h, --help A short help text. -L, --license Show the license and exit. -xSUFFIX Search only files ending with SUFFIX, e.g. ``.txt''. May be specified multiple times. -i, --ignore-case Ignore the case of old_string. -w, --whole-words Make old_string match only on word boundaries. -b, --backup Move the original files to filename~ before replacing them. -q, --quiet Quiet mode. -v, --verbose Verbose mode. -s, --dry-run Simulation mode, no files are changed. -R, --recursive Recurse into subdirectories. -e, --escape Expand escape sequences in old_string and new_string. Examples of escape sequences are ' ' (new-line), ' ' (tab), 'x42' (hexadec- imal number 42), '33' (octal number 033). -p, --prompt Prompt for confirmation before replacing each file. -f, --force Ignore errors when trying to restore permissions and file ownership. -d, --keep-times Keep modification times when replacing files. -t, --use-tmpdir Use a temporary directory for storing temporary files, usually the value of the environment variable TMPDIR. The default is to put temporary files in the same directory as the file being modified. -a, --all Do not ignore files and directories starting with . IMPLEMENTATION NOTES
An effort has been made to make the program behave as much as the original rpl as necessary. Where it has been possible to make improve- ments, improvements have been made. This implementation lacks many of the bugs in the original. EXAMPLES
Replace all occurences of ``F'' (on word boundaries) with ``A'' in all text files under the grades/ directory: $ rpl -Rwd -x'.txt' 'F' 'A' grades/ SEE ALSO
find(1), sed(1). HISTORY
This program was written for Debian as a free replacement for the non-free rpl program by Joe Laffey. AUTHORS
Goran Weinholt <weinholt@debian.org>. Debian July 31, 2005 Debian
All times are GMT -4. The time now is 04:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy