Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

How to filter values from a list in JSON with jq where some Id value does not start with value

$
0
0

I would like to filter DNSNames where Id does not start with the DNSName.

Given the following JSON:

[    {"Id": "9580cf2dd3161c0e33d8c04a4e84384e28784af65e55c1e84899d9da797902be","NetworkSettings": {"Networks": {"nextcloud-aio": {"IPAddress": "172.18.0.10","DNSNames": ["nextcloud-aio-whiteboard","9580cf2dd316"                    ]                }            }        }    }]

if I execute the following query:

jq -r '.[]|"\(.NetworkSettings.Networks[].IPAddress|select(length > 0) // "# no ip address:") \(if .NetworkSettings.Networks[].DNSNames != null then (.NetworkSettings.Networks[].DNSNames|join(" ")) else (.Name|sub("^/"; "")|sub("_1$"; "")) end)"'

I get the following result:

172.18.0.10 nextcloud-aio-whiteboard 9580cf2dd316

How can I filter out 9580cf2dd316 based in the Id9580cf2dd3161c0e33d8c04a4e84384e28784af65e55c1e84899d9da797902be so I get the following result?

172.18.0.10 nextcloud-aio-whiteboard

Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>