java - 仅 Grep 字符串中某些模式后的几个数字

标签 java string grep

我有一个如下所示的 xml 文件

<testsuite name="org.eclipse.app4mc.addon.multicore.cpurta.tests.CPURtaIATest" time="2.489" tests="1" errors="0" skipped="0" failures="0">
<testsuite name="org.eclipse.app4mc.addon.multicore.cpurta.tests.EventChainLatencyTest" time="0.491" tests="2" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="org.eclipse.app4mc.addon.multicore.rta.tests.CommonUtilsTest" time="0.02" tests="16" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="org.eclipse.app4mc.addon.multicore.rta.tests.RuntimeUtilTest" time="0" tests="0" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="org.eclipse.app4mc.addon.multicore.rta.tests.BlockingTest" time="0.303" tests="4" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="org.eclipse.app4mc.addon.multicore.rta.tests.GPUSchedulingTest" time="1.855" tests="2" errors="0" skipped="0" failures="0">
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="org.eclipse.app4mc.addon.multicore.rta.tests.ContentionTest" time="0.271" tests="2" errors="0" skipped="0" failures="0">

这些是 Maven Surefire 报告的第二行(xml 报告)仅供引用,使用此后得到的

find ./littleRTA/**/target/surefire-reports -name '*.xml' -exec awk 'NR==2' {} \; > totalText.txt` 

在 gitlab-ci

我想获取行尾关键字timeerrortests等后面的数字,并将它们放入csv 文件,所以在我的 csv 中它会像这样

0.271, 2, 0, 0, 0

或者也许只是将它们放入文本文件中。考虑尝试 grep 但文件名可以包含任何这些关键字

最佳答案

这就是你想做的事吗?

$ awk -F'"' -v OFS=, '{print $(NF-9), $(NF-7), $(NF-5), $(NF-3), $(NF-1)}' file
2.489,1,0,0,0
0.491,2,0,0,0
0.02,16,0,0,0
0,0,0,0,0
0.303,4,0,0,0
1.855,2,0,0,0
0.271,2,0,0,0

关于java - 仅 Grep 字符串中某些模式后的几个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57778415/

相关文章:

java - LogCat条目含义

string - 任何对字符串进行破坏/散列但可以匹配的算法?

regex - 使用正则表达式 Grep 比特币地址

regex - 如何grep一个shell变量来匹配行尾?

regex - 使用 GREP 过滤

java - Hibernate无法将java.lang.Integer字段com.XXX.XXX.XXX.Cooperative.id设置为java.util.ArrayList

optimization - Java API 方法运行时间

java - 如何禁用向自身发送好友请求的按钮?

java - 根据关键字拆分字符串

android - 如何将 EditText 日期拆分为 Calendar 对象的年、月和日整数?