Perl如何读取日志文件更新的内容
2个回答
展开全部
#!/usr/bin/perl
#取文件行数
##循环开始清空文件
if (-f "tmp.out"){
open FILE,">tmp.out";
close FILE;}
open( A, "<", "count.txt" );
while (<A>) {
$count = $_;
};
print "上次记录的记录数为$count\n";
open(my $fh, '<', 'catalina.out');
$. = 0;
while (<$fh>) {
($num=$.) if eof;
};
print "文件最新的记录数为$num"."\n";
open( B, ">", "count.txt" );
print B ("$num\n");
if ( defined($count) && $num != $count && $num !=0 )
{print "开始处理\n";
open( C, "<", "catalina.out" ) || die "$!\n";
while (<C>) {
if ($. > "$count" ){
open( D, ">>", "tmp.out" );
print D ("$_\n");
}
}};
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询