Perl One Liner Regex

时间:2014-10-16 12:16:07

标签: regex perl file

我需要将文件中的结果记录到屏幕上。

cat logfile.txt

=====================Installing Oracle========================
*** ERROR[Install023] Oracle is already installed in $VOL1.
Alert: There might be an issue, Please check!
=============================================
=====================File Set verification========================
Filesystem    State    512-blocks       Used       Avail  Capacity  Mounted on
HOME          STARTED   143372688   119516872    23855816   83%    /home
BIN       STOPPED        -           -           -        -    /nfsT/nfsdata/common
ROOT          STARTED   143372688   119516872    23855816   83%    /
TEMP          STARTED   143372688   118402344    24970344   83%    /tmp
The Filset for home directory looks Ok.
The Filset for root directory looks Ok.
=============================================

我在做:

perl -0777 -nle  'print $2 "\n" while m/^(={21})([\w\s]+)(+={24})/gm' logfile.txt

但它没有给出任何结果。

输出需要。

Installing Oracle..... Alert
File Set verification.....Ok!

1 个答案:

答案 0 :(得分:1)

不清楚警报的所有可能原因是什么,但以下适用于您的样本:

perl -ne 'undef $err, print "$1 ..." if /^={21}([^=]+)={24}/;
          $err = 1 if /ERROR/;
          print $err ? "Alert" : "Ok!", "\n" if /={45}/'