我有一个需要正确格式化为可读格式的日志文件。但是,文本文件没有静态行数或固定的主要值,并且具有随机数量的空格,但只有一个日志文件头,可用于确定每次应用程序日志的开始和结束。
日志文件示例:
Log File header
<text>
<text>
Log File header
<text>
脚本格式化后应该如下所示:
Log File header
<text>
<text>
<space>
Log File header
<text>
<text>
因此,每次 Perl 脚本检测到“日志文件头”时,我都需要一些关于找出整个段落的建议。
这是 grep perl 脚本:
#!/usr/bin/perl
#use 5.010; # must be present to import the new 5.10 functions, notice
#that it is 5.010 not 5.10
my $file = "/root/Desktop/Logfiles.log";
open LOG, $file or die "The file $file has the error of:\n => $!";
@lines = <LOG>;
close (LOG);
@array = grep(/Log File header/, @lines);
print @array;
有人可以就代码提供一些建议吗?谢谢。