I'm writing this jq request to output info about cpu:
cat kubernetes.txt | jq 'fromjson.kubernetes.pod | .name, .cpu.usage.nanocores'
My output is:
"podname"
null
"podname1"
null
"podname2"
null
"podname3"
3345678
"podname3"
123456
How to output only strings with values
You can leverage the select
function for this:
cat kubernetes.txt | jq 'fromjson.kubernetes.pod | select(.cpu.usage.nanocores != null) | .name, .cpu.usage.nanocores'
https://stedolan.github.io/jq/manual/#Builtinoperatorsandfunctions