Re: Help in finding group of text



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
.



Relevant Pages

  • Re: Send an email on . . .
    ... touch of genius - and a lot of courage to move in the opposite direction." ... --Albert Einstein ...
    (Debian-User)
  • Re: calculate average
    ... Any intelligent fool can make things bigger and ... It takes a touch of genius - ... and a lot of courage to move in the opposite ...
    (perl.beginners)
  • Re: regex question
    ... Any intelligent fool can make things bigger and ... It takes a touch of genius - ... and a lot of courage to move in the opposite ...
    (perl.beginners)
  • Re: the art of pkgdb -F
    ... How the hell am I supposed to know?? ... takes a touch of genius - and a lot of courage to move in the opposite ...
    (freebsd-questions)