hi all,
I have a need to write a perl script to do the following
1. read a log file
2. search the logfile.txt for a specific string, in this case the stri
+ng "TWO"
3. extract record that contains the string "TWO" from log file into an
+other file
I tried this example but it does not work as what i wish
#!/usr/bin/perl -w
use strict;
use IO::File;
use constant FILE => 'b2bclient-gateway-heartbeat.log';
use constant FIND => 'production';
IO::File->input_record_separator(FIND);
my $fh = IO::File->new(FILE, O_RDONLY) or die 'Could not open file ',
+FILE, ": $!";
$fh->getline;
#fast forward to the first match, print each occurence in the file
print IO::File->input_record_separator
while $fh->getline;
$fh->close;
======================================
The logfile.txt ooks like this
============================
2007-Nov-07 00:00:00 UTC (GMT +0000) - Poll: channel = ONE, ref =
2007-Nov-07 00:00:01 UTC (GMT +0000) - Poll: channel = TWO, ref =
2007-Nov-07 00:00:01 UTC (GMT +0000) - Poll: channel = TWO, ref =
2007-Nov-07 00:00:02 UTC (GMT +0000) - Poll: channel = THREE, ref =
2007-Nov-07 00:00:02 UTC (GMT +0000) - Poll: channel = TWO, ref =
2007-Nov-07 00:00:03 UTC (GMT +0000) - Poll: channel = TWO, ref =
2007-Nov-07 00:00:03 UTC (GMT +0000) - Poll: channel = TWO, ref =
2007-Nov-07 00:00:04 UTC (GMT +0000) - Poll: channel = TWO, ref =
Thanks - TuaKiLan
tuakilan@gmail.com