我正在写这个jq请求来输出有关cpu的信息:
cat kubernetes.txt | jq 'fromjson.kubernetes.pod | .name, .cpu.usage.nanocores'
我的输出是:
"podname"
null
"podname1"
null
"podname2"
null
"podname3"
3345678
"podname3"
123456
如何只输出值
的字符串您可以利用select
函数:
cat kubernetes.txt | jq 'fromjson.kubernetes.pod | select(.cpu.usage.nanocores != null) | .name, .cpu.usage.nanocores'
https://stedolan.github.io/jq/manual/Builtinoperatorsandfunctions