Solution:
In perl this type of problems or requirement can be easily solved because of its versatility.
my $line='';
open(FILE,'/home/lalit/Desktop/test.txt') or die "Could not open file " . $!;
while (<FILE>){
if($_ =~ /how are you/ig){
print "\nprevious line of matching pattern =>" . $line;
print "\nCurrent Line of matching pattern =>" . $_;
print "\nNext Line of matching pattern =>" . scalar <FILE>."\n";
}
$line = $_;
}
close FILE;
In perl this type of problems or requirement can be easily solved because of its versatility.
my $line='';
open(FILE,'/home/lalit/Desktop/test.txt') or die "Could not open file " . $!;
while (<FILE>){
if($_ =~ /how are you/ig){
print "\nprevious line of matching pattern =>" . $line;
print "\nCurrent Line of matching pattern =>" . $_;
print "\nNext Line of matching pattern =>" . scalar <FILE>."\n";
}
$line = $_;
}
close FILE;
This is really good . i am sure this will help me a lot.. !! thanks ...Still guessing wt scalar does ther ?? Got to google it out.
ReplyDeleteThanks a lot :)