if statements

I am trying to change this :

Albert Einstein 52
Peter Scott 22
Hilary Smith 48
Joan Bakewell 30
Catherine Maguire 26

into

Albert Einstein Pass
Peter Scott Fail
Hilary Smith Pass
Joan Bakewell Fail
Catherine Maguire Fail

I have to use a if statement that says:

if field 3 is greater then 40
then change field 3 to pass
else change field 3 to fail
endif

but i am failing badly can any please help

Here is one perl script. Check for errors then have a try.

#!/usr/bin/perl

$PassMark = 40;
$InputFile = "filename";
$OutPutFile = "results";

open (INPUTFILE, "$InputFile") || die "Error Reason $!";
@DATA=<INPUTFILE>;
close(INPUTFILE);

open (RESULTFILE, ">$OutPutFile") || die "Error Reason $!";

foreach $Record(@DATA) {
chomp($Record);
my($Fname, $Sname, $Mark) = split(/ /, $Record);

if($Mark >= $PassMark) {
print RESULTFILE "$Fname $Sname PASS\n"; $s++;
} else {
print RESULTFILE "$Fname $Sname FAIL\n"; $f++;
}
}
close(RESULTFILE);

print "$f students Passed, $f Failed(don't hate them :slight_smile: )\n";
exit;

GoodLuck..!!

One of the virtues of Unix, There is More Than One Way TO Do It:

awk '{if($3>40) print $1" "$2" pass"; else print $1" "$2" fail"}' <I>input_file</I>