0

我正在尝试使用 findstr ,其输入来自带有引号的管道输出,并且命令放置在 perl 脚本中。我无法匹配双引号。例如:我的 out of java 命令类似于:

<violation beginline="30" endline="171" begincolumn="8" endcolumn="1" rule="something" ruleset="AllRules" package="com.mypackage priority="3">
<violation beginline="30" endline="171" begincolumn="8" endcolumn="1" rule="something" ruleset="AllRules" package="com.mypackage priority="5">

    our $currentViolationCount=`java Myclass | FINDSTR -i "priority=\"3\""`

我尝试使用 FINDSTR -i ^"priority=\"3\"^" 和 FINDSTR -i ^"priority=\^"3\^"^",但它不匹配任何行

4

2 回答 2

0

或作为 cmdline oneliner:

java Myclass|perl -wnpi -e 's/.*priority="(\d+)".*/$1/g
于 2013-09-18T21:00:17.230 回答
0

使用 Perl 处理输出。不要忘记错误检查!

our $currentViolationCount=`java Myclass`;
if ($?){die "java Myclass is died, error: $!";}
my ($priority)=$currentViolationCount=~m!priority="\d+"!gis;
print "Found priority: $priority\r\n";
于 2013-09-18T09:13:17.367 回答