In python I can do:
>>> 5 in [2,4,6]
False
>>> 5 in [4,5,6]
True
to determine if the give value 5
exists in the list. I want to do the same concept in jq
. But, there is no in
. Here is an example with a more realistic data set, and how I can check for 2 values. In my real need I have to check for a few hundred and don't want to have all those or
ed together.
jq '.[] | select(.PrivateIpAddress == "172.31.6.209"
or
.PrivateIpAddress == "172.31.6.229")
| .PrivateDnsName' <<EOF
[
{
"PrivateDnsName": "ip-172-31-6-209.us-west-2.compute.internal",
"PrivateIpAddress": "172.31.6.209"
},
{
"PrivateDnsName": "ip-172-31-6-219.us-west-2.compute.internal",
"PrivateIpAddress": "172.31.6.219"
},
{
"PrivateDnsName": "ip-172-31-6-229.us-west-2.compute.internal",
"PrivateIpAddress": "172.31.6.229"
},
{
"PrivateDnsName": "ip-172-31-6-239.us-west-2.compute.internal",
"PrivateIpAddress": "172.31.6.239"
}
]
EOF