我是 perl 新手,我需要开发一个脚本来对目录中的日志进行排序,获取最新文件并仅从日志文件中复制特定内容并将其打印到新文件中。我写了一个下面的 perl 脚本我需要你的宝贵意见。
my($dir) = "C:\Luntbuild_Logs\LACOPBOC LACOPBOC_LASQABOCFC_";
$file = #Here i want to pick up the last generated log file from the above dir
my($newLog) = "new.log";
while (<MYFILE>) {
print "$line" if $line =~ /> @/;
print "$line" if $line =~ /ORA-/;
}
close (MYFILE);
I want my code to pick up the last generated log file from the dir and print the specific lines and redirect the output to the new log file.
您能否在下面的代码中更正我现在我的 srript 能够排序和打印最新文件(目录中的所有文件都是 txt 文件)但我无法执行该操作
use File::stat;
$dirname = 'C:/Luntbuild_Logs';
$timediff=0;
opendir DIR, "$dirname";
while (defined ($file = readdir(DIR)))
{
if($file ne "." && $file ne "..")
{
$diff = time()-stat("$dirname/$file")->mtime;
if($timediff == 0)
{
$timediff=$diff;
$newest=$file;
}
if($diff<$timediff)
{
$timediff=$diff;
$newest=$file;
}
}
}
open(FILE,"<$newest");
my(@fprint) = <FILE>;
close FILE;
open(FOUT,">list1.txt") || die("Cannot Open File");
foreach $line (@fprint) {
print "$line" if $line =~ /> @/;
print "$line" if $line =~ /ORA-/;
print FOUT $line;
}
close FOUT;