The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




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

Join Date: Dec 2006
Posts: 50
Assistance needed with perl script

Ok, theres a log file containing the below. Lets call the logfile log_fantastic:

2009/03/16 21:42:45 USER: tonnabo - MAC: 0014BF2D385A - STATUS_ID: 30 - STATE: ERROR
2009/03/16 21:42:45 USER: tonnabo - MAC: 001310AC120D - STATUS_ID: 15 - STATE: OK
2009/03/16 21:42:45 USER: tonnabo - MAC: 001DD9277095 - STATUS_ID: 20 - STATE: ERROR


I want to write a perl script that will read the contents of log_fantastic and output only the lines that does not have a status_id of 10?

the below is what i've done. not sure if this is correct:


use Data:: Dumper;

main();


sub main {
my @results;
my $headers = "user,
mac address,
status_id";

my (@log_info, @dircontents);


open (LOG, "</home/jhenson/log_fantastic");
@log_info = <LOG>;
close (LOG);

print Dumper("testing");
foreach my $content (@log_info) {
chomp($content);
my $line = substr ($content, -2);
print Dumper($line);
if ($line eq "OK") {
push @dircontents, $content;
}
}


#push @alarm_info, uc $headers;

print Dumper(@dircontents);

}