
입력.json
{
"Stack": {
"KeypairNameB651C0C1": "key-0123456abcdefg",
"AsgNameA7D05B90": "my-asg-name"
}
}
키 이름은 다양할 수 있지만 항상 설정된 문자열로 시작됩니다.
유제여기select(startswith("AsgName"))
하지만 어떻게든열쇠
jq를 구현할 수 있나요?
답변1
키를 사용 to_entries
/ 액세스 할 수 있습니다 .with_entries
$ jq '.Stack | with_entries(select(.key | startswith("AsgName")))' file.json
{
"AsgNameA7D05B90": "my-asg-name"
}
또는
$ jq '.Stack | to_entries[] | select(.key | startswith("AsgName")) | .value' input.json
"my-asg-name"