尝试使用findstr,其输入来自具有引号的管道输出,并且命令放在perl scropt中。我无法匹配双引号。例如:我的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 \ ^“^”,但它不匹配任何行
答案 0 :(得分: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";
答案 1 :(得分:0)
或者作为cmdline oneliner:
java Myclass|perl -wnpi -e 's/.*priority="(\d+)".*/$1/g