Linux JQ.如何从特定ID条目中提取数据
伙计,长期关注这个董事会并学到了很多东西,但现在遇到了一些问题。我正在使用读取 json 的 Linux shell 脚本(这里没问题)。我想做的是从具有特定类型的条目中获取值。
通过仅使用 jq -r '.'
解析 json,我得到
{
"records": [
{
"id": 01,
"type": "SOA",
"name": "@",
"data": "1800",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
},
{
"id": 02,
"type": "A",
"name": "@",
"data": "test.com",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
],
"links": {},
"meta": {
"total": 2
}
}
然后,我使用 "jq -r '.records' "
并得到:
[
{
"id": 01,
"type": "SOA",
"name": "@",
"data": "1800",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
},
{
"id": 02,
"type": "A",
"name": "@",
"data": "test.com",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
]
我需要做什么是获取类型A的数据值。目前,我们有类型SOA和A,但我只需要从A获取数据。
我可以使用“jq -r '.records[1].data'的虚拟方式” 和它给了我
test.com
的正确响应,但我想要一种更动态的方式来搜索特定类型(在本例中为“A”),然后给出数据值。
谢谢你们!
Guy, long term looking at this board and learning a lot but now stuck with little issue. Im working with Linux shell script that reads json (no problem here). What Im trying to do is get value from entry that has specific Type.
By parsing a json with just jq -r '.'
, I get
{
"records": [
{
"id": 01,
"type": "SOA",
"name": "@",
"data": "1800",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
},
{
"id": 02,
"type": "A",
"name": "@",
"data": "test.com",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
],
"links": {},
"meta": {
"total": 2
}
}
Then, I use "jq -r '.records' "
and get:
[
{
"id": 01,
"type": "SOA",
"name": "@",
"data": "1800",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
},
{
"id": 02,
"type": "A",
"name": "@",
"data": "test.com",
"priority": null,
"port": null,
"ttl": 1800,
"weight": null,
"flags": null,
"tag": null
}
]
What I need to do is get data value of the type A. Currently, we have type SOA and A, but I need to only get data from A.
I can use dummy way of "jq -r '.records[1].data'"
and it gives me correct response of test.com
, but I want a more dynamic way of searching for specific type (in this case "A") and then giving the data value.
Thanks guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该字段名为
domain_records
还是只是records
?使用
select
来匹配您的条件演示
Is the field called
domain_records
or justrecords
?Use
select
to match your criteriaDemo