如何使用外壳脚本从文本文件中获取选定值

6vl6ewon  于 2022-09-19  发布在  Linux
关注(0)|答案(0)|浏览(130)

我有一个如下所示的文件(myfile.txt)

{"projectStatus":{"status":"ERROR","conditions":[{"status":"ERROR","metricKey":"new_bugs","comparator":"GT","periodIndex":1,"errorThreshold":"0","actualValue":"2"},
{"status":"ERROR","metricKey":"new_reliability_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"3"},
{"status":"ERROR","metricKey":"new_security_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"2"},
{"status":"OK","metricKey":"new_maintainability_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},
{"status":"ERROR","metricKey":"new_code_smells","comparator":"GT","periodIndex":1,"errorThreshold":"0","actualValue":"17"},
{"status":"ERROR","metricKey":"new_vulnerabilities","comparator":"GT","periodIndex":1,"errorThreshold":"0","actualValue":"2"},
{"status":"ERROR","metricKey":"coverage","comparator":"LT","errorThreshold":"90","actualValue":"80.3"},
{"status":"ERROR","metricKey":"new_coverage","comparator":"LT","periodIndex":1,"errorThreshold":"90","actualValue":"7.826086956521739"}],
"periods":[{"index":1,"mode":"previous_version","date":"2021-11-04T14:47:41+0000"}],"ignoredConditions":false}}

我必须选择"actualValue":"7.826086956521739""metricKey":"new_coverage"

则预期输出为(实际值)

7.826086956521739

这就是我试过的

sed -n 's/"metricKey":"new_coverage" "actualValue": //p' myfile.txt

有谁能帮我弄清楚这件事吗?提前谢谢!

注意:我不允许使用JQ或通用脚本语言(JavaScript、Python等)。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题