我有一个如下所示的 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
我想获取行尾关键字time
、error
、tests
等后面的数字,并将它们放入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/