通过命令行获取包含多个 JSON 的数组中包含的键的值
我有一个数组,里面包含很多 json 。我想在该数组中搜索与包含名称的 json 位于同一位置的 uuid 值:
"name":"120GB"
我需要一些实际查看数组内部并获取 uuid 值的东西。我不知道这是否可以通过Linux 命令行实现。我想了很久,不知道如何下手。
这是数组,有时包含 "name:120GB" 的 json 位于第一位,有时位于第二位,等等。
这里是数组:
[
{
"uuid": "c70c1627-71ec-46c8-8ce1-43055adcb606",
"name": "DESCARGAS",
"comment": "",
"mntentref": "7be7b356-177a-4436-802a-2e7b785d52b6",
"reldirpath": "DESCARGAS/",
"privileges": "",
"_used": true,
"device": "6TBNAS",
"description": "DESCARGAS [on 6TBNAS, DESCARGAS/]",
"mntent": {
"devicefile": "/dev/sdc1",
"fsname": "/dev/disk/by-uuid/c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"dir": "/srv/dev-disk-by-uuid-c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "70593bb6-0876-436c-bdd7-3b401fb55d50",
"name": "MUSICA",
"comment": "",
"mntentref": "6c59b572-faf0-4682-85e8-ad92eaa6d34a",
"reldirpath": "MUSICA/",
"privileges": "",
"_used": true,
"device": "3TBNAS",
"description": "MUSICA [on 3TBNAS, MUSICA/]",
"mntent": {
"devicefile": "/dev/sdb1",
"fsname": "/dev/disk/by-uuid/2cac8ffa-bca4-4564-904f-cae65e56b650",
"dir": "/srv/dev-disk-by-uuid-2cac8ffa-bca4-4564-904f-cae65e56b650",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "f0a0aa62-2a97-4cee-86d9-55961a675978",
"name": "NINA",
"comment": "",
"mntentref": "6c59b572-faf0-4682-85e8-ad92eaa6d34a",
"reldirpath": "NINA/",
"privileges": "",
"_used": true,
"device": "3TBNAS",
"description": "NINA [on 3TBNAS, NINA/]",
"mntent": {
"devicefile": "/dev/sdb1",
"fsname": "/dev/disk/by-uuid/2cac8ffa-bca4-4564-904f-cae65e56b650",
"dir": "/srv/dev-disk-by-uuid-2cac8ffa-bca4-4564-904f-cae65e56b650",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "7fe35e3b-8cbe-43f3-ad72-d0710ce6e0e7",
"name": "COMPARTIR",
"comment": "",
"mntentref": "7be7b356-177a-4436-802a-2e7b785d52b6",
"reldirpath": "COMPARTIR/",
"privileges": "",
"_used": true,
"device": "6TBNAS",
"description": "COMPARTIR [on 6TBNAS, COMPARTIR/]",
"mntent": {
"devicefile": "/dev/sdc1",
"fsname": "/dev/disk/by-uuid/c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"dir": "/srv/dev-disk-by-uuid-c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "abbaca32-09a2-410b-9918-dd1d0ee66273",
"name": "120GB",
"comment": "",
"mntentref": "1157e369-73a4-4c61-b8d2-7cbccc207a11",
"reldirpath": "/",
"privileges": "",
"_used": false,
"device": "120GB_ANTIGUO",
"description": "120GB [on 120GB_ANTIGUO, /]",
"mntent": {
"devicefile": "/dev/sdd1",
"fsname": "/dev/disk/by-uuid/269E8B449E8B0B8D",
"dir": "/srv/dev-disk-by-uuid-269E8B449E8B0B8D",
"type": "ntfs",
"posixacl": false
}
}
]
如何获取 uuid 的值?我希望我已经很好地解释了自己。
I have an array that contains many json inside. I want to search within that array for the uuid value that is in the same position as the json that contains the name:
"name":"120GB"
I need something that actually looks inside the arrays and gets the value of uuid. I don't know if this will be possible through the Linux command line. I've been thinking about it for a long time and I don't know how to get my hands on it.
This is the array, sometimes the json containing the "name:120GB" is in the first place, sometimes in the second, etc.
Here the array:
[
{
"uuid": "c70c1627-71ec-46c8-8ce1-43055adcb606",
"name": "DESCARGAS",
"comment": "",
"mntentref": "7be7b356-177a-4436-802a-2e7b785d52b6",
"reldirpath": "DESCARGAS/",
"privileges": "",
"_used": true,
"device": "6TBNAS",
"description": "DESCARGAS [on 6TBNAS, DESCARGAS/]",
"mntent": {
"devicefile": "/dev/sdc1",
"fsname": "/dev/disk/by-uuid/c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"dir": "/srv/dev-disk-by-uuid-c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "70593bb6-0876-436c-bdd7-3b401fb55d50",
"name": "MUSICA",
"comment": "",
"mntentref": "6c59b572-faf0-4682-85e8-ad92eaa6d34a",
"reldirpath": "MUSICA/",
"privileges": "",
"_used": true,
"device": "3TBNAS",
"description": "MUSICA [on 3TBNAS, MUSICA/]",
"mntent": {
"devicefile": "/dev/sdb1",
"fsname": "/dev/disk/by-uuid/2cac8ffa-bca4-4564-904f-cae65e56b650",
"dir": "/srv/dev-disk-by-uuid-2cac8ffa-bca4-4564-904f-cae65e56b650",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "f0a0aa62-2a97-4cee-86d9-55961a675978",
"name": "NINA",
"comment": "",
"mntentref": "6c59b572-faf0-4682-85e8-ad92eaa6d34a",
"reldirpath": "NINA/",
"privileges": "",
"_used": true,
"device": "3TBNAS",
"description": "NINA [on 3TBNAS, NINA/]",
"mntent": {
"devicefile": "/dev/sdb1",
"fsname": "/dev/disk/by-uuid/2cac8ffa-bca4-4564-904f-cae65e56b650",
"dir": "/srv/dev-disk-by-uuid-2cac8ffa-bca4-4564-904f-cae65e56b650",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "7fe35e3b-8cbe-43f3-ad72-d0710ce6e0e7",
"name": "COMPARTIR",
"comment": "",
"mntentref": "7be7b356-177a-4436-802a-2e7b785d52b6",
"reldirpath": "COMPARTIR/",
"privileges": "",
"_used": true,
"device": "6TBNAS",
"description": "COMPARTIR [on 6TBNAS, COMPARTIR/]",
"mntent": {
"devicefile": "/dev/sdc1",
"fsname": "/dev/disk/by-uuid/c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"dir": "/srv/dev-disk-by-uuid-c8175ed0-e2a8-473f-846c-36e5dc79e4bd",
"type": "ext4",
"posixacl": true
}
},
{
"uuid": "abbaca32-09a2-410b-9918-dd1d0ee66273",
"name": "120GB",
"comment": "",
"mntentref": "1157e369-73a4-4c61-b8d2-7cbccc207a11",
"reldirpath": "/",
"privileges": "",
"_used": false,
"device": "120GB_ANTIGUO",
"description": "120GB [on 120GB_ANTIGUO, /]",
"mntent": {
"devicefile": "/dev/sdd1",
"fsname": "/dev/disk/by-uuid/269E8B449E8B0B8D",
"dir": "/srv/dev-disk-by-uuid-269E8B449E8B0B8D",
"type": "ntfs",
"posixacl": false
}
}
]
How could I get the value of uuid? I hope I have explained myself well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
jq
提取uuid:示例输出:
仅uuid:
示例输出:
或者:
You can extract the uuid using
jq
:sample output:
Only the uuid:
sample output:
Or: