[英]JQ : Parse specific output (get IP) from JSON file
I want to get the IPs that has 'server.sh' value.我想获取具有“server.sh”值的 IP。 My current script gets all the IPs我当前的脚本获取所有 IP
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"]
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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.