我有一个文本文件读取为数组。我正在检查此数组的每一行,并尝试在Perl脚本中提取该行的一部分(如果它与模式匹配)。
---
Message '/com/java/deploy/mess1' on folder1 'f1' is running.
Additional thread instances: '0'
Deployed: '11/12/13 1:54 AM' in Jar file '/deploy/ENV/folder1/mess1ENV11122013.jar'
Last edited: '5/24/13 4:38 PM'.
Long description: ''
---
Message '/com/java/deploy/mess2' on folder1 'f1' is running.
Additional thread instances: '0'
Deployed: '11/12/13 1:54 AM' in Jar file '/deploy/ENV/folder1/mess2ENV11122013.jar'
Last edited: '5/24/13 4:38 PM'.
Long description: ''
----
Message '/com/java/deploy/mess3' on folder1 'f1' is running.
Additional thread instances: '0'
Deployed: '11/12/13 1:54 AM' in Jar file '/deploy/ENV/folder1/mess3ENV11122013.jar'
Last edited: '5/24/13 4:38 PM'.
Long description: ''
我正在搜索mess1并试图从上面的数组中提取jar信息。
foreach $line (@messdetials) {
if ($line =~ mess1) {
next if /^(\s)*$/;
if (/in Jar file '(.*?)'/) {
@jardetails = `$displaycommand -b $1`;
print @jardetails;
}
我希望从数组中提取/deploy/ENV/folder1/mess1.jar
并对其运行内部脚本,但我看不到任何输出。
答案 0 :(得分:0)
这会按照你的要求行事。它期望inpu文件的路径作为命令行上的参数,如此
perl findjar.pl /path/to/mylog.log
<强> findjar.pl 强>
use strict;
use warnings;
my $mess;
while (<>) {
if ( /^\s*Message\s*'([^']*)'/ ) {
$mess = $1;
}
elsif ( /in Jar file '([^']*)'/ ) {
print $1, "\n" if $mess and $mess eq 'mess1';
}
}
<强>输出强>
/deploy/ENV/folder1/mess1.jar
答案 1 :(得分:-1)
我可以使用以下代码段实现此目的。
if ($line=~/$flowname/){$flag=1;}
if($flag==1){
if ($line =~/in Jar file '([^']*)'/){
@jardetails = `$displaycommand -b $1`;
print @jardetails;
}
$flag=0;}
这对我有用。