Sunday, 19 May 2013

Grepping a particular range of word in a file using perl script

USAGE: perl filename $startingword $lastword $filename

use warnings;
$file=$ARGV[2];
open(FILE,"$file");
$first=$ARGV[0];
$second=$ARGV[1];
while($line=<FILE>)
{
$e++;
if($line=~/$first/)
{
$f=$e;
}
elsif($line=~/$second/)
{
$s=$e;
}
}
close(FILE);
open(FILE1,"$file");
while(<FILE1>)
{
$w++;
if(($w>$f)&&($w<$s))
{
print $_."\n";
}
}
close(FILE1);

No comments:

Post a Comment