in reply to How to read a text file, extract a records that contains a string, export the result into a temporary file

Or if you're on a windows machine without grep perl -ne'print if /TWO/' b2bclient-gateway-heartbeat.log > output.txt

If it is part of a larger task then

my $in_file = 'b2bclient-gateway-heartbeat.log'; open my $in_fh, '<', $in_file or die "Could not open file $in_file: $! +"; my $out_file = 'output.txt'; open my $out_fh, '>', $out_file or die "Could not open file $out_file: + $!"; while ( my $line = <$in_fh> ) { print {$out_fh} $line if $line =~ /TWO/; } close $in_fh or die "Could not close file $in_file: $!"; close $out_fh or die "Could not close file $out_file: $!";

  • Comment on Re: How to read a text file, extract a records that contains a string, export the result into a temporary file
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: How to read a text file, extract a records that contains a string, export the result into a temporary file
by tuakilan (Acolyte) on Feb 15, 2008 at 02:55 UTC
    hipowls, thanks for your tip, it works for one of the tasks that i need to perform on the text file. regards - tuakilan