Friday, 17 May 2013

Greping exact word in a file using perl script ( Border usage)

USAGE: perl "script file" "word to grep" "file name where you going to perform the action"

#!/usr/bin/perl
$word=$ARGV[0];
$file=$ARGV[1];
open(FILE,"$file");
while($line=<FILE>)
{
if($line=~/\b$word\b/ )
{
print $line."\n";
}
}
close(FILE);

No comments:

Post a Comment