gpt4 book ai didi

json - JQ : Parse specific output (get IP) from JSON file

转载 作者:行者123 更新时间:2023-12-04 19:00:02 24 4
gpt4 key购买 nike

我想获取具有“server.sh”值的 IP。我当前的脚本获取所有 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"
}
}
}

测试.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"]

最佳答案

你的任务可以吗?

jq '.nodes|.[]|select(.":server"=="server.sh")|.":ip"+":4648"' test.json 
"192.168.56.30:4648"
"192.168.56.31:4648"

关于json - JQ : Parse specific output (get IP) from JSON file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60983197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com