The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what these statements means namishtiwari UNIX for Dummies Questions & Answers 1 01-17-2008 02:20 AM
Automate SQL statements panchpan SUN Solaris 3 01-03-2008 02:32 AM
Please help on IF statements. filthymonk Shell Programming and Scripting 4 07-18-2007 06:59 AM
Else in If Statements chapmana UNIX for Dummies Questions & Answers 8 11-30-2006 08:07 AM
or statements? Blip Shell Programming and Scripting 1 01-19-2004 04:08 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-22-2001
lilas lilas is offline
Registered User
  
 

Join Date: Mar 2001
Posts: 2
Angry

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
  #2 (permalink)  
Old 03-22-2001
mib mib is offline
Registered User
  
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
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 )\n";
exit;

GoodLuck..!!



  #3 (permalink)  
Old 03-22-2001
PxT's Avatar
PxT PxT is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2000
Location: Sacramento, CA
Posts: 909
One of the virtues of Unix, There is More Than One Way TO Do It:

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0