azure-cli - 使用 jmespath 过滤嵌套数组(使用 az cli)
问题描述
我想知道 TXT 记录中的值是否已在 DNS 中可用:
az network dns record-set txt show -g myresourcegroup -z 'mydomain' -n 'mytxtvalues'
这是 json 结果的一部分:
"txtRecords": [
{
"value": [
"abc"
]
},
{
"value": [
"def"
]
}
]
我尝试了很多查询。这些是我希望工作的 2 个。
az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query txtRecords[?value[?starts_with(@, 'abc')]]
az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query txtRecords[*].value[?starts_with(@, 'abc')]]
结果是:
在 line:1 char:123 + ... 'mytxtvalues' --query txtRecords[?value[?starts_with(@, 'abc') ... + ~ 源文本中无法识别的标记。在 line:1 char:124 + ... 'mytxtvalues' --query txtRecords[?value[?starts_with(@, 'abc')] ... + ~ 参数列表中缺少参数。
看起来用于过滤数组的 @ 无法识别。但我不知道如何查询。
知道值 abc 是否已经在列表中的正确查询是什么?
解决方案
您需要使用如下命令:
az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query "txtRecords[*].value[?starts_with(@, 'abc')]"
如果您只需要输出字符串,您可以附加参数-o tsv
。希望这会帮助你。
推荐阅读
- core-data - Index Beyond Bounds / EXC_BAD_ACCESS 核心数据删除 SwiftUI
- vue.js - 使用 v-for 将动态创建的元素上的 @click 事件限制为调用它的元素
- javascript - 错误:元素类型无效,需要字符串(对于内置组件)或类/函数(对于复合元素)
- javascript - Puppeteer 浏览器和页面即时关闭,page.evaluate 不适用于 bloc 2
- database - 限制 MariaDB 中小数点后的位置数
- laravel - 在我报告错误后修复 - laravel 新项目 --auth 不会创建 HomeController.php
- azure - 使用 U-SQL 读取列数未知的 Excel 文件时如何避免最后一列值重复
- c# - 如何使用包含“ODM”之类的值的 C# 在 excel 中过滤整个列?
- java-stream - 为什么 Hybris modelService.save() 在 ifPresent() 方法中不起作用?
- windows-7 - CDATA [Microsoft.PointOfService.PosControlException:消息访问端口'COM10'被拒绝。/(另一个错误''通信(端口)故障''