JQ 命令返回不同数据的重复 ID

JQ 命令返回不同数据的重复 ID

今天,我尝试将值输入到我们的程序中,但我一直得到重复的结果。

curl -s http://cd0a4a.ethosdistro.com/?json=yes|jq -r '["version", "GPU_driver", "miner", "gpu", "rigname"],(.rigs[] | [.version, .driver, .miner, "\(.gpus)/\(.miner_instance)","0d6b27"])| @csv' | csvlook -I 

给出结果:

| version | GPU_driver | miner    | gpu | rigname |
| ------- | ---------- | -------- | --- | ------- |
| 1.2.3   | nvidia     | ethminer | 2/2 | 0d6b27  |
| 1.2.4   | amdgpu     | ethminer | 1/1 | 0d6b27  |

与预期结果相反:

| version | GPU_driver | miner    | gpu | rigname |
| ------- | ---------- | -------- | --- | ------- |
| 1.2.3   | nvidia     | ethminer | 2/2 | 0d6b27  |
| 1.2.4   | amdgpu     | ethminer | 1/1 | 50dc35  |

答案1

您可以使用to_entries[]来获取 json 密钥。(通过

这对我有用:

curl -s http://cd0a4a.ethosdistro.com/?json=yes \
| jq -r '["version", "GPU_driver", "miner", "gpu", "rigname"],(.rigs | to_entries[] | [.value.version, .value.driver, .value.miner,"\(.value.gpus)/\(.value.miner_instance)", .key]) | @csv' \
| csvlook

相关内容