#!/usr/bin/perl -w
printf"write the path you want to search files:";
$searchdir=<STDIN>;
chomp $searchdir;
printf "Input search string:";
$searchstr=<STDIN>;
chomp $searchstr;
opendir(DIRHANDLE,$searchdir) || die "Cann't open $searchdir !";
while($file=readdir DIRHANDLE) {
if (-d "$searchdir/$file") {
printf "$searchdir/$file is a directory!\n";
} else {
open(FileHandle, "$searchdir/$file") || die "cann't open $searchdir/$file !\n";
$lines=1;
while (defined($line=<FileHandle>)) {
$back=index($line,$searchstr);
if ( $back != -1 ) {
print"$file:$lines:$line";
}
$lines=$lines+1;
}
}
close(FileHandle);
}
closedir(DIRHANDLE);