$searchdir=”c:/folder”; #指定根文件夹路径
chomp $searchdir;
$searchstr=”N2O_emission”; #指定欲提取的字符串
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);