The UNIX and Linux Forums  


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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 03-07-2009
ldapswandog ldapswandog is offline
Registered User
  
 

Join Date: Feb 2009
Location: Charlotte, NC
Posts: 101
A better way using perl
=========================================
#!/usr/bin/perl -w

$PORT=0;
$OPEN=0;
$TRANS=0;
$FAIL=0;

unless (open(INPUT, "<test5.txt")) {
die ("cannot open input, check permissions\n");
}
unless (open(OUTPUT, ">output.txt")) {
die ("cannot open output, check permissions\n");
}
while ($line = <INPUT>) {
if ($line =~ /200/) {
$PORT++;
}
elsif ($line =~ /150/) {
$OPEN++;
}
elsif ($line =~ /226/) {
$TRANS++;
}
elsif ($line =~ /not connected/i) {
$FAIL++;
}
}
print OUTPUT "PORT: $PORT\n";
print OUTPUT "OPEN: $OPEN\n";
print OUTPUT "TRANS: $TRANS\n";
print OUTPUT "FAIL: $FAIL\n";

close (INPUT);
close (OUTPUT);