Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays jq基于值提取数组键_Arrays_Jq - Fatal编程技术网

Arrays jq基于值提取数组键

Arrays jq基于值提取数组键,arrays,jq,Arrays,Jq,考虑到这一点: { "{c156e78e-a4ac-422b-bf86-afe12f548dfb}": { "name": "after-gluster3.8", "date": "2017-04-16 14:31:20", "state": "poweron", "current": false, "parent": "" } , "{d773d5b7-94d4-4f78-a943-

考虑到这一点:

{
    "{c156e78e-a4ac-422b-bf86-afe12f548dfb}": {
        "name": "after-gluster3.8",
        "date": "2017-04-16 14:31:20",
        "state": "poweron",
        "current": false,
        "parent": ""
    }
    ,
    "{d773d5b7-94d4-4f78-a943-f50e4eb68fe0}": {
        "name": "after-sshd-fixes",
        "date": "2017-04-16 16:58:32",
        "state": "poweroff",
        "current": true,
        "parent": "{c156e78e-a4ac-422b-bf86-afe12f548dfb}"
    }
}
我需要根据name的值提取密钥,即在sshd修复后搜索
,然后希望
“{d773d5b7-94d4-4f78-a943-f50e4eb68fe0}”作为输出

使用
[]
会扔掉数组的键,我对jq手册的其余部分有些不知所措,我想知道如何将数组的键放入一个临时值,进行测试,然后输出特定的数组键:value

jq方法:

jq 'to_entries[] | select(.value.name == "after-sshd-fixes").key' jsonfile
输出:

"{d773d5b7-94d4-4f78-a943-f50e4eb68fe0}"

下面是我想回答的问题,请看你的:
cat file.json | jq'带有_条目(.value.test+=.key)|.[]|选择(.name==”在sshd修复之后”)'| jq-r.test'