从json jq输出的前缀URL

时间:2020-01-29 03:37:52

标签: json bash jq yq

团队, 我已经输出了,我想用一个URL作为前缀。

kubectl get nodes -l nodeGroup=gpu -o wide --no-headers -o json | jq '.items[] | .metadata.name, .metadata.labels."team.com/cordon-reason"' | awk '{print $1}' | paste - -

输出

"node1" "testing"
"node2" null

预期产量

"node1" "https://jira.test.com/testing"
"node2" "https://jira.test.com/null"

2 个答案:

答案 0 :(得分:0)

aah:刚刚想通了,但这是正确的方法吗?

-o json | jq '.items[] | .metadata.name, .metadata.labels."test.com/cordon-reason"' | awk '{print $1}' | paste - - | xargs -l1 -- sh -c 'echo $1 https://jira.test.com/$2' --

输出

node1 https://jira.test.com/testing
node2 https://jira.test.com/null

答案 1 :(得分:0)

随心所欲地看着我

jq -r '.items[] | [.metadata.name, "https://jira.test.com/\(.metadata.labels["test.com/cordon-reason"])"] | @tsv'