Sponsored Content
Top Forums Shell Programming and Scripting Bourne Script, sorting and getting average of file Post 302505638 by DualPandas on Thursday 17th of March 2011 01:18:53 PM
Old 03-17-2011
Bourne Script, sorting and getting average of file

Hi I am trying to get a bourne shell script to sort a file for me. Here is what i currently have:
Code:
#/bin/sh
echo "Name   Exam1   Exam2   Exam3  Total  Grade" > final.txt
awk -f 9.awk grades.txt | sort +4 -5 >> final.txt

Code:
#BEGIN {printf "Name\tExam1\tExam2\tExam3\tTotal\tGrade";}
{
        if($2+$3+$4>90) {printf "%s\t%d\tA\n",$0,$4+$2+$3;}
        else
                if(($2+$3+$4>=80)&&($2+$3+$4<90)) {printf "%s\t%d\tB\n",$0,$2+$3+$4;}
                else
                if(($2+$3+$4>=70)&&($2+$3+$4<80)) {printf "%s\t%d\tC\n",$0,$2+$3+$4;}
                        else
                if(($2+$3+$4>=50)&&($2+$3+$4<70)) {printf "%s\t%d\tD\n",$0,$2+$3+$4;}
                  else {printf "%s\t%d\tF\n",$0,$2+$3+$4;}
}


This is what I want it to look like when done:
Code:
Name Exam1 Exam2 Exam3 Total Average Grade
Brian   38   38   40   116   96   A
Jack    30   35   38   103   85   B
Lisa    30   28   32   90    75   C
Nick    33   30   15   78    65   C
Jane    31   25   19   75    62   D
Tom     23   12   30   65    54   D
Karen   25   28   12   65    54   D

and this is what it looks like right now:
Code:
Name   Exam1   Exam2   Exam3  Total  Average  Grade
Name	Exam1	Exam2	Exam3	0	F
Jack	30	35	38	103	A
Brian	38	38	40	116	A
Karen	25	28	12	65	D
Tom	23	12	30	65	D
Jane	31	25	19	75	C
Nick	33	30	15	78	C
Lisa	30	28	32	90	F

right now it is sorting on the total column. which is wrong,I know I need to have it sort on the average column, however I cant get it to display an average. How do i get it to calculate the average? Also I have the extra line of Name Exam1.. etc that I cant get rid of.

Any help would be much appreciated.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Bourne shell script need help please ?

i have this assignment.. and i mad this script but there is something wrong with it.. if anyone can tell me.. watz going on... i would appreciate it.. tHnX in advance.. count=1 val=$2 op=$1 ans=0 if then if then while do ... (7 Replies)
Discussion started by: dezithug
7 Replies

2. Shell Programming and Scripting

simple bourne script

Hello There, I am trying to write this SIMPLE script in Bourne Shell but I keep on getting a blank response. Can you see what I am doing wrong? I am simply trying to take the day of the week from our system and when the teachers sign on I want them to see the message of the day, when they exe... (2 Replies)
Discussion started by: catbad
2 Replies

3. Shell Programming and Scripting

bourne script help

I need to make a small script that figures out if a filename that the user enters is a file or a directory. and if it is a directory, how many files are in it. please point me to the right direction, I am a newbie at this. (1 Reply)
Discussion started by: Heedunk
1 Replies

4. Shell Programming and Scripting

Bourne Script help

Hey guys, I am trying to do a bourne script to look for c files in the current directory. I had it working where it finds the files and asks you to delete them or not, which works, but if there i no files, then it comes up with errors, which iam trying to get rid of. So I thought I would do a if... (2 Replies)
Discussion started by: Pits
2 Replies

5. Shell Programming and Scripting

help with bourne script

Hey guys not sure why but when i execute the script i get the correct result but then it says command not found not sure why can anyone see anything wrong with my code below? I just want to print how much quota i have used in my home directory #!bin/sh `quota -v | grep ^/home | awk... (2 Replies)
Discussion started by: musicmancanora4
2 Replies

6. Shell Programming and Scripting

Calculate average from CSV file using PERL script

Hi All I have this csv file and I need to calculate the average of FPS. FPS:27.7420, Interval:1314184238772 FPS:25.9798, Interval:1314184242646 FPS:27.4772, Interval:1314184246311 FPS:26.1623, Interval:1314184250159 FPS:26.4515, Interval:1314184253972 FPS:31.5896, Interval:1314184257163... (24 Replies)
Discussion started by: sayachop
24 Replies

7. Shell Programming and Scripting

Open a file from within a Bourne shell Script

I am suppose to make a program that cuts the extension off of a file. It uses that .ext to decide which program needs to be used to open the file. This only finds the name of the program from a list of programs I made. My problem is when it has the name of the program it needs to use, how can I... (3 Replies)
Discussion started by: dordrix
3 Replies

8. Shell Programming and Scripting

awk based script to find the average of all the columns in a data file

Hi All, I need the modification for the below mentioned code (found in one more post https://www.unix.com/shell-programming-scripting/27161-script-generate-average-values.html) to find the average values for all the columns(but for a specific rows) and print the averages side by side. I have... (4 Replies)
Discussion started by: ks_reddy
4 Replies

9. Shell Programming and Scripting

Script to load daily average I/O stats from a .ksh file into Oracle db

Hi can anyone help me with a script to load output of the .ksh file into an Oracle database. I have attached sample output of the information that i need to load to the database (2 Replies)
Discussion started by: LucyYani
2 Replies

10. Shell Programming and Scripting

Help needed: script for timely average from log file

Please repost your query: Help needed: script for timely average from log file - Thank you. (0 Replies)
Discussion started by: mkfs
0 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 04:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy