Reputation: 3969
I want to get the IPs that has 'server.sh' value. My current script gets all the IPs
test.json
{
"nodes": {
"test1.local": {
":ip": "192.168.56.30",
":server": "server.sh",
":client": "client.sh"
},
"test2.local": {
":ip": "192.168.56.31",
":server": "server.sh",
":client": "client.sh"
},
"test3.local": {
":ip": "192.168.56.32",
":client": "client.sh"
}
}
}
test.sh
ips=`jq -c '.nodes | to_entries | map(.value.":ip")| map_values(.+":4648")' test.json`
echo $ips
["192.168.56.30:4648","192.168.56.31:4648","192.168.56.32:4648"]
Upvotes: 0
Views: 1255
Reputation: 506
Is it ok for your task?
jq '.nodes|.[]|select(.":server"=="server.sh")|.":ip"+":4648"' test.json
"192.168.56.30:4648"
"192.168.56.31:4648"
Upvotes: 2