【发布时间】:2021-09-01 14:51:20
【问题描述】:
我有这个 JSON 文件:
{
"range": "Sheet!A2:B100",
"majorDimension": "ROWS",
"values": [
[
"customer1_name",
"customer1@email.com",
"customer1_phone",
"customer1_city"
],
[
"customer2_name",
"customer2@email.com",
"customer2_phone",
"customer2_city"
]
]
}
而且,我想从一个 shell 脚本中使用 JQ 来提取每个块的每个值并将它们分配给一些变量。这是预期的结果:
对于这个块:
[
"customer1_name",
"customer1@email.com",
"customer1_phone",
"customer1_city"
],
结果应该是这样的:
VAR1 = "customer1_name"
VAR2 = "customer1@email.com"
VAR3 = "customer1_phone"
VAR4 = "customer1_city"
对于这个块:
[
"customer2_name",
"customer2@email.com",
"customer2_phone",
"customer2_city"
],
结果应该是这样的:
VAR1 = "customer2_name"
VAR2 = "customer2@email.com"
VAR3 = "customer2_phone"
VAR4 = "customer2_city"
想法是逐块读取 JSON 文件以获取/检索 VARS 中的所有值。
有什么意见或建议吗?
谢谢
【问题讨论】:
-
我发现了这个:jq -r '.values | .[1]' 但是现在如何逐个提取值?
标签: json linux shell jq script