Re: Help in finding group of text
- From: jwkrahn@xxxxxxx ("John W. Krahn")
- Date: Fri, 23 Dec 2011 22:26:13 -0800
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
.
- References:
- Help in finding group of text
- From: Saravanan Murugaiah
- Help in finding group of text
- Prev by Date: Re: Help in finding group of text
- Next by Date: Re: segmentation fault
- Previous by thread: Re: Help in finding group of text
- Index(es):
Relevant Pages
|