develooper Front page | perl.beginners | Postings from December 2011

Re: Help in finding group of text

Thread Previous | Thread Next
From:
John W. Krahn
Date:
December 23, 2011 22:26
Subject:
Re: Help in finding group of text
Message ID:
4EF57085.3000802@shaw.ca
Saravanan Murugaiah wrote:
> Dear All,

Hello,

> In my text file, the following occurrence are there:
>
> begin
> some of group of text some of group of text some of group of text
> some of group of text some of group of text some of group of text
> some of group of text some of group of text some of group of text
> some of group of text some of group of text some of group of text
> end
>
> In this, I need to search the contents from "begin" to "end" and it should
> be copied into an another file. I tried but all went wrongly. Kindly
> suggest in this regard.

#!/usr/bin/perl
use warnings;
use strict;


my $input_file  = 'my text file';
my $output_file = 'another file';


open my $IN_FH,  '<', $input_file  or die "Cannot open '$input_file' 
because: $!";
open my $OUT_FH, '>', $output_file or die "Cannot open '$output_file' 
because: $!";


while ( <$IN_FH> ) {
     if ( /^begin/ .. /^end/ ) {
         print $OUT_FH $_;
         }
     }


close $OUT_FH;
close $IN_FH;


__END__


John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About