![JQ 命令返回不同数据的重复 ID](https://linux22.com/image/896124/JQ%20%E5%91%BD%E4%BB%A4%E8%BF%94%E5%9B%9E%E4%B8%8D%E5%90%8C%E6%95%B0%E6%8D%AE%E7%9A%84%E9%87%8D%E5%A4%8D%20ID.png)
今天,我尝试将值输入到我们的程序中,但我一直得到重复的结果。
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