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 =
In reply to How to read a text file, extract a records that contains a string, export the result into a temporary file by tuakilan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |