
03-17-2009
|
|
Shell programmer, author
|
|
|
Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,372
|
|
Quote:
Originally Posted by lazypeterson
|
Not that it matters in this instance, but see these pages:
Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful
Quote:
|
Code:
awk 'BEGIN { print "Name Exam1 Exam2 Exam 3 Total Grade" }' grades | tee gradesorted
|
Why two awk programs?
Quote:
Code:
awk '{if ($2+$3+$4<50){grade="F"}else if ($2+$3+$4>49 && $2+$3+$4<65)
{grade="D"}else if ($2+$3+$4>64 && $2+$3+$4<80){grade="C"}
else if ($2+$3+$4>79 && $2+$3+$4<90){grade="B"}else{grade="A"}}
{print $0, " ", $2+$3+$4, " ", grade;}' grades | tee gradesorted
What I'm trying to do change both the prints so that what's in the quotations gets appended to the file rather than printed to the screen. I've tried using sed with no success. Can anyone point me in the right direction?
|
Code:
#!/bin/sh
awk 'BEGIN {
format = "%-15s%-15s%-15s%-15s\n"
printf format, "Name", "Exam1", "Exam2", "Exam 3", "Total", "Grade"
}
{
total = $2 + $3 + $4
if (total < 50) {grade = "F"}
else if (total < 65) {grade = "D"}
else if (total < 80) {grade = "C"}
else if (total < 90) {grade = "B"}
else {grade="A"}
}
{printf format, $1, $2, $3, $4, total, grade}' grades > gradesorted
|