首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Windows命令行从这个类似json的文件中获取数据?

如何使用Windows命令行从这个类似json的文件中获取数据?
EN

Stack Overflow用户
提问于 2021-08-25 10:55:26
回答 1查看 21关注 0票数 0

我想要从这个json(-like?)捕获total_hashrate数据。Windows中的文件:

代码语言:javascript
复制
{
  "miner": {
    "devices": [
      {
        "accepted_shares": 326,
        "core_clock": 1299,
        "core_utilization": 100,
        "fan": 85,
        "hashrate": "53.98 M",
        "hashrate2": "0.000 ",
        "hashrate2_raw": 0,
        "hashrate_raw": 53977101.17434701,
        "id": 0,
        "info": "NVIDIA GeForce RTX 3070 Ti",
        "invalid_shares": 0,
        "mem_clock": 10541,
        "mem_utilization": 100,
        "pci_bus_id": 3,
        "power": 179,
        "rejected_shares": 1,
        "temperature": 62
      },
      {
        "accepted_shares": 445,
        "core_clock": 1029,
        "core_utilization": 99,
        "fan": 95,
        "hashrate": "78.68 M",
        "hashrate2": "0.000 ",
        "hashrate2_raw": 0,
        "hashrate_raw": 78678367.75194064,
        "id": 1,
        "info": "NVIDIA GeForce RTX 3080 Ti",
        "invalid_shares": 0,
        "mem_clock": 10541,
        "mem_utilization": 100,
        "pci_bus_id": 7,
        "power": 272,
        "rejected_shares": 2,
        "temperature": 63
      },
      {
        "accepted_shares": 229,
        "core_clock": 1166,
        "core_utilization": 100,
        "fan": 85,
        "hashrate": "42.82 M",
        "hashrate2": "0.000 ",
        "hashrate2_raw": 0,
        "hashrate_raw": 42818658.5005993,
        "id": 2,
        "info": "NVIDIA GeForce RTX 2070",
        "invalid_shares": 0,
        "mem_clock": 7693,
        "mem_utilization": 89,
        "pci_bus_id": 11,
        "power": 124,
        "rejected_shares": 1,
        "temperature": 59
      }
    ],
    "total_hashrate": "175.5 M",
    "total_hashrate2": "0.000 ",
    "total_hashrate2_raw": 0,
    "total_hashrate_raw": 175474127.42688695,
    "total_power_consume": 575
  },
  "reboot_times": 0,
  "start_time": 1629840480,
  "stratum": {
    "accepted_shares": 1000,
    "algorithm": "ethash",
    "difficulty": "8.590 G",
    "dual_mine": false,
    "invalid_shares": 0,
    "latency": 38,
    "pool_hashrate_10m": "343.6 M",
    "pool_hashrate_24h": "185.4 M",
    "pool_hashrate_4h": "200.6 M",
    "rejected_shares": 4,
    "url": "es.xxxx.com:1800",
    "use_ssl": false,
    "user": "xxxx.yyyy"
  },
  "version": "39.1"
}

我已经尝试过这个命令:

jq-win64.exe '.total_hashrate‘json.txt

但它返回一条错误消息:

jq:错误:语法错误,意外的INVALID_CHARACTER,预期的$end (Windows cmd shell引用问题?)在,第1行:'.total_hashrate‘jq: 1编译错误

我试过这个:

jq-win64.exe.[].total_hashrate json.txt

它返回带有"“not I want:

"175.5 M“jq: error (at json.txt:86):无法为字符串为"total_hashrate”的数字编制索引

EN

回答 1

Stack Overflow用户

发布于 2021-08-25 11:41:37

好的,我已经找到路了:

代码语言:javascript
复制
jq-win64.exe -r .miner.total_hashrate json.txt > total_hashrate.txt
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68921558

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档