tuakilan has asked for the wisdom of the Perl Monks concerning the following question:
I tried this example but it does not work as what i wish1. 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
====================================== The logfile.txt ooks like this ============================#!/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;
Thanks - TuaKiLan tuakilan@gmail.com2007-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 =
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to read a text file, extract a records that contains a string, export the result into a temporary file
by hipowls (Curate) on Feb 14, 2008 at 09:34 UTC | |
by tuakilan (Acolyte) on Feb 15, 2008 at 02:55 UTC | |
|
Re: How to read a text file, extract a records that contains a string, export the result into a temporary file
by svenXY (Deacon) on Feb 14, 2008 at 09:35 UTC | |
|
Re: How to read a text file, extract a records that contains a string, export the result into a temporary file
by Punitha (Priest) on Feb 14, 2008 at 09:39 UTC | |
|
Re: How to read a text file, extract a records that contains a string, export the result into a temporary file
by apl (Monsignor) on Feb 14, 2008 at 10:51 UTC | |
|
Re: How to read a text file, extract a records that contains a string, export the result into a temporary file
by Anonymous Monk on Feb 14, 2008 at 09:21 UTC |