json 如何使用max_by查找数组中包含最大值的父键(及其兄弟键)?

jogvjijk  于 2023-04-22  发布在  其他
关注(0)|答案(1)|浏览(93)

我试着在这两个命令中使用max_by来得到我想要的东西。

#1. cat file | jq '[.tx[].vout[]] | max_by(.value)'
#2. cat file | jq '[.tx[]] | max_by(.vout[].value)'

这两个命令给了我不同的最大值。(value键有float值。注意我也尝试使用“tonumber”选项,但没有什么特别的发生)#1输出总是正确的,但它的输出不包括父键。#2输出有时得到正确的答案,有时没有,但它包括我想要的父键。
谁能告诉我出了什么问题?
Json示例:

{
  "hash": "00000000000000000001241066f08f95165581bcfc9bf322cb8fe2bfb6b2f06c",
  "confirmations": 1,
  "height": 786329,
  "version": 591831040,
  "versionHex": "2346a000",
  "merkleroot": "93fae4566cf6de6321e0cd1ed4ab9ac600189d26d7d61ef6c41487752344bf49",
  "time": 1682050350,
  "mediantime": 1682049479,
  "nonce": 3398206502,
  "bits": "1705c739",
  "difficulty": 48712405953118.43,
  "chainwork": "00000000000000000000000000000000000000004630bda1645c6b5192c287b4",
  "nTx": 1800,
  "previousblockhash": "0000000000000000000266435d01b562713c63d22844afbc2ddabfeaabab0ed0",
  "strippedsize": 751963,
  "size": 1737058,
  "weight": 3992947,
  "tx": [
    {
      "txid": "273baace700870d378d68b9d386520f0b3b3796521748c36b6f494865725728a",
      "hash": "c7fc6635d004cc714b5395e370b7287a76ad3ae7c59bad86f92701852dd46504",
      "version": 2,
      "size": 214,
      "vsize": 187,
      "weight": 748,
      "locktime": 0,
      "vin": [
        {
          "coinbase": "0399ff0b042e0d42642f466f756e6472792055534120506f6f6c202364726f70676f6c642f03e2e49b2e58000000000000",
          "txinwitness": [
            "0000000000000000000000000000000000000000000000000000000000000000"
          ],
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 6.36518171,
          "n": 0,
          "scriptPubKey": {
            "asm": "0 35f6de260c9f3bdee47524c473a6016c0c055cb9",
            "hex": "001435f6de260c9f3bdee47524c473a6016c0c055cb9",
            "address": "bc1qxhmdufsvnuaaaer4ynz88fspdsxq2h9e9cetdj",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 0.00000000,
          "n": 1,
          "scriptPubKey": {
            "asm": "OP_RETURN aa21a9edb389e4fde6f6da8aa655288ffc460e8c00a169fa9420a496fdc1e60bf4dcf8d7",
            "hex": "6a24aa21a9edb389e4fde6f6da8aa655288ffc460e8c00a169fa9420a496fdc1e60bf4dcf8d7",
            "type": "nulldata"
          }
        }
      ],
      "hex": "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff310399ff0b042e0d42642f466f756e6472792055534120506f6f6c202364726f70676f6c642f03e2e49b2e58000000000000ffffffff021b7ff0250000000016001435f6de260c9f3bdee47524c473a6016c0c055cb90000000000000000266a24aa21a9edb389e4fde6f6da8aa655288ffc460e8c00a169fa9420a496fdc1e60bf4dcf8d70120000000000000000000000000000000000000000000000000000000000000000000000000"
    },
    {
      "txid": "82cad0c8bf23f1e0ada86df5e4cbcd508245ab45618f2424ac4f354445ae1e81",
      "hash": "45512a05a5ca929e23364a7f06a0fa10defed2ebdc77e74f1e9d08cc64245b6b",
      "version": 1,
      "size": 414,
      "vsize": 224,
      "weight": 894,
      "locktime": 0,
      "vin": [
        {
          "txid": "a1a842e9de8482e84e42a096396465e1c2367101b5676a4b94404c8e39fc784c",
          "vout": 2,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "",
            "30440220222e21db0d6ef8e7541ba89ac706128cf5cddd1154420d2236532c00b69d406f02201563447fb0d612fab8565a6b694b904a1fe0212b45d0eb0b0a120b95c0c70e5601",
            "304402200d885f1bb76de47ba636fa2e2370a017d563da6a4f269fd4a9bc4a1e0bda4e360220592a248b2f6b1b894becba1eb3452438ea164a4a27201bd8d760f47d0692e56401",
            "52210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae"
          ],
          "sequence": 4294967295
        }
      ],
      "vout": [
        {
          "value": 0.02400000,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_HASH160 e0bd422a0555d8cfad1bdbf2781830a0329e442c OP_EQUAL",
            "hex": "a914e0bd422a0555d8cfad1bdbf2781830a0329e442c87",
            "address": "3NBL1RQjEr4vDbqmSMWeV64oDge7dSRRGp",
            "type": "scripthash"
          }
        },
        {
          "value": 0.00160719,
          "n": 1,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 57155f4180f1f0a1b15c8f473ddb2cd9103171c5 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a91457155f4180f1f0a1b15c8f473ddb2cd9103171c588ac",
            "address": "18wTPebwqMZDqujSZfj8fchFRTP65Ynvoj",
            "type": "pubkeyhash"
          }
        },
        {
          "value": 0.01845731,
          "n": 2,
          "scriptPubKey": {
            "asm": "0 701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d",
            "hex": "0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d",
            "address": "bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej",
            "type": "witness_v0_scripthash"
          }
        }
      ],
      "fee": 0.00040000,
      "hex": "010000000001014c78fc398e4c40944b6a67b5017136c2e165643996a0424ee88284dee942a8a10200000000ffffffff03009f24000000000017a914e0bd422a0555d8cfad1bdbf2781830a0329e442c87cf730200000000001976a91457155f4180f1f0a1b15c8f473ddb2cd9103171c588ace3291c0000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d04004730440220222e21db0d6ef8e7541ba89ac706128cf5cddd1154420d2236532c00b69d406f02201563447fb0d612fab8565a6b694b904a1fe0212b45d0eb0b0a120b95c0c70e560147304402200d885f1bb76de47ba636fa2e2370a017d563da6a4f269fd4a9bc4a1e0bda4e360220592a248b2f6b1b894becba1eb3452438ea164a4a27201bd8d760f47d0692e564016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000"
    },
    {
      "txid": "802ef44673ff9c90bae2a9790aba0a71176cef71f5c7dfde723401beecef6d5a",
      "hash": "41b3672f668abdb721289fe91d894a40bff1424123ee008ee4b7fe1d438b3dc5",
      "version": 2,
      "size": 223,
      "vsize": 141,
      "weight": 562,
      "locktime": 0,
      "vin": [
        {
          "txid": "79d114144fea2914a5019967dba85ff34d5ee897d34ae1bf5216c2ac49fe738d",
          "vout": 3,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "3045022100cee123978849318825c437d2965bb89177cf4efe3a1729fb5eaee8bc18911b9602200d7c9ac92eb8339489509ea3306f1a897dbec757507c61bb943252cb540bf79701",
            "026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea286"
          ],
          "sequence": 4294967293
        }
      ],
      "vout": [
        {
          "value": 0.00600000,
          "n": 0,
          "scriptPubKey": {
            "asm": "0 afb3eb8b9edbcc83709b374d1c581c1e263dcad5",
            "hex": "0014afb3eb8b9edbcc83709b374d1c581c1e263dcad5",
            "address": "bc1q47e7hzu7m0xgxuymxax3ckqurcnrmjk4vlr8mh",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 8.89321842,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "hex": "0014f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "address": "bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00022032,
      "hex": "020000000001018d73fe49acc21652bfe14ad397e85e4df35fa8db679901a51429ea4f1414d1790300000000fdffffff02c027090000000000160014afb3eb8b9edbcc83709b374d1c581c1e263dcad572f9013500000000160014f60834ef165253c571b11ce9fa74e46692fc5ec102483045022100cee123978849318825c437d2965bb89177cf4efe3a1729fb5eaee8bc18911b9602200d7c9ac92eb8339489509ea3306f1a897dbec757507c61bb943252cb540bf7970121026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea28600000000"
    },
    {
      "txid": "d007aa4ef0fdd0add723551e4e43a7214692491c0dd44d8bb93bffd44c9799da",
      "hash": "758e37a729cc6ab78c8f5eb9ad360b2b93836ce0c850db5689aca2d258d08f4a",
      "version": 2,
      "size": 223,
      "vsize": 141,
      "weight": 562,
      "locktime": 0,
      "vin": [
        {
          "txid": "763ae3655896af8102d50e536d74f8a4643cb31153c7b3479dde2cff286cf83e",
          "vout": 1,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "3045022100c707a290598ead494f7c0ae0cca6e7c352b64910975a796148d11a42f47405e80220557d67f1f35a1c10b8ef27ba85b841779dd0c405d3f5f7c5e3bc9e573943e3e701",
            "02076c2a3862869b95bdadfaaf8bf3376b6ee4bf450aca9587aaa961f7b22533df"
          ],
          "sequence": 4294967293
        }
      ],
      "vout": [
        {
          "value": 0.08400000,
          "n": 0,
          "scriptPubKey": {
            "asm": "0 86a1c36b7ec85975f1d852f0c39e69d16b736373",
            "hex": "001486a1c36b7ec85975f1d852f0c39e69d16b736373",
            "address": "bc1qs6sux6m7epvhtuwc2tcv88nf694hxcmnmzt670",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 14.32349940,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 16ee7494a93f327c10afe94c04fdcb1dc3744600",
            "hex": "001416ee7494a93f327c10afe94c04fdcb1dc3744600",
            "address": "bc1qzmh8f99f8ue8cy90a9xqflwtrhphg3sq76srhe",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00022032,
      "hex": "020000000001013ef86c28ff2cde9d47b3c75311b33c64a4f8746d530ed50281af965865e33a760100000000fdffffff02802c80000000000016001486a1c36b7ec85975f1d852f0c39e69d16b736373f4ec5f550000000016001416ee7494a93f327c10afe94c04fdcb1dc374460002483045022100c707a290598ead494f7c0ae0cca6e7c352b64910975a796148d11a42f47405e80220557d67f1f35a1c10b8ef27ba85b841779dd0c405d3f5f7c5e3bc9e573943e3e7012102076c2a3862869b95bdadfaaf8bf3376b6ee4bf450aca9587aaa961f7b22533df00000000"
    },
    {
      "txid": "7cb5c8d5e9aecac1b96bd17d9cbbfa32a2a692f6fae997f648953a8aa92bc74f",
      "hash": "9320dbabfa8449c8f124ad90296e9b5f7f39c30735750f4e79a32bb25ec4969c",
      "version": 2,
      "size": 254,
      "vsize": 173,
      "weight": 689,
      "locktime": 0,
      "vin": [
        {
          "txid": "6c90ce72395ae4b8a15f7569fc1824a6f7b11fd6ad80ed4ddf01a7d72d1616a7",
          "vout": 3,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "304402200f29e2be998dd991460dbaafc639cf5ca031a0057f099f56052b44297c6206cf0220488e696aed1503aac68e3fb916e2304b1681ad5e4265b8f571c898afd92e96f701",
            "026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea286"
          ],
          "sequence": 4294967293
        }
      ],
      "vout": [
        {
          "value": 0.00375950,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_HASH160 6feb94fd2b9e4e9d1afb90c5c09340c578d5e410 OP_EQUAL",
            "hex": "a9146feb94fd2b9e4e9d1afb90c5c09340c578d5e41087",
            "address": "3Bto9MriAUnocAzE36yL7GUshApeSMw9iq",
            "type": "scripthash"
          }
        },
        {
          "value": 0.00949735,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 00914aa5f061ac9f5f542ec580c619e48c829b86",
            "hex": "001400914aa5f061ac9f5f542ec580c619e48c829b86",
            "address": "bc1qqzg54f0svxkf7h659mzcp3seujxg9xux6lgx38",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 5.93817769,
          "n": 2,
          "scriptPubKey": {
            "asm": "0 f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "hex": "0014f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "address": "bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00026928,
      "hex": "02000000000101a716162dd7a701df4ded80add61fb1f7a62418fc69755fa1b8e45a3972ce906c0300000000fdffffff038ebc05000000000017a9146feb94fd2b9e4e9d1afb90c5c09340c578d5e41087e77d0e000000000016001400914aa5f061ac9f5f542ec580c619e48c829b86a9f0642300000000160014f60834ef165253c571b11ce9fa74e46692fc5ec10247304402200f29e2be998dd991460dbaafc639cf5ca031a0057f099f56052b44297c6206cf0220488e696aed1503aac68e3fb916e2304b1681ad5e4265b8f571c898afd92e96f70121026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea28600000000"
    },
    {
      "txid": "b080e7e39d6db4414a25c8c37b642a00e5e5c29592b3ef475754448ccccfb75e",
      "hash": "5127274b6b27919c7cbb14620089c68b2b572156a555a790a8c04c5ad09bc94f",
      "version": 2,
      "size": 317,
      "vsize": 235,
      "weight": 938,
      "locktime": 0,
      "vin": [
        {
          "txid": "99342b19982f6a2d9a244cc2b22884cea413ec5d682a6d8e1a17f88bcfd7b14e",
          "vout": 3,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "3045022100cfdf46bf202f8806570a6afbafcfd0672619d5432533748f0641f88befb1f1790220321b248dea29c2b832c799f40de041e2dabb020e751a76814f61272c9123526d01",
            "026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea286"
          ],
          "sequence": 4294967293
        }
      ],
      "vout": [
        {
          "value": 0.01880000,
          "n": 0,
          "scriptPubKey": {
            "asm": "0 e59390350f807c6930f5711e61f68a94fadc910f",
            "hex": "0014e59390350f807c6930f5711e61f68a94fadc910f",
            "address": "bc1qukfeqdg0sp7xjv84wy0xra52jnadeyg04zgldm",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 0.00392486,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 ecd18d448745fb48b6423f5b2c1cc381e593fee5",
            "hex": "0014ecd18d448745fb48b6423f5b2c1cc381e593fee5",
            "address": "bc1qangc63y8gha53djz8adjc8xrs8je8lh92nalf5",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 0.03725620,
          "n": 2,
          "scriptPubKey": {
            "asm": "0 7e60bff1b82c59aa482c0a4b32e90373ff59dd6b",
            "hex": "00147e60bff1b82c59aa482c0a4b32e90373ff59dd6b",
            "address": "bc1q0estludc93v65jpvpf9n96grw0l4nhttxjdcg5",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 0.00495770,
          "n": 3,
          "scriptPubKey": {
            "asm": "OP_HASH160 6dc9a2c492c64090bc5cc4a6ddc2ff87be61a000 OP_EQUAL",
            "hex": "a9146dc9a2c492c64090bc5cc4a6ddc2ff87be61a00087",
            "address": "3BhX8MYo2Xb9T46GF5m8BfzmXGWSMPpnx1",
            "type": "scripthash"
          }
        },
        {
          "value": 4.25211103,
          "n": 4,
          "scriptPubKey": {
            "asm": "0 f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "hex": "0014f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "address": "bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00036414,
      "hex": "020000000001014eb1d7cf8bf8171a8e6d2a685dec13a4ce8428b2c24c249a2d6a2f98192b34990300000000fdffffff05c0af1c0000000000160014e59390350f807c6930f5711e61f68a94fadc910f26fd050000000000160014ecd18d448745fb48b6423f5b2c1cc381e593fee534d93800000000001600147e60bff1b82c59aa482c0a4b32e90373ff59dd6b9a9007000000000017a9146dc9a2c492c64090bc5cc4a6ddc2ff87be61a00087df34581900000000160014f60834ef165253c571b11ce9fa74e46692fc5ec102483045022100cfdf46bf202f8806570a6afbafcfd0672619d5432533748f0641f88befb1f1790220321b248dea29c2b832c799f40de041e2dabb020e751a76814f61272c9123526d0121026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea28600000000"
    },
    {
      "txid": "e741044ca9a20a860c8f64f43aab9834d61e76370cd81d2963ee48bd3f731e01",
      "hash": "b2ccc985c58632a0bd4acffde1e26c984c48c9a87ecb323959f9ccfb90a0d99c",
      "version": 2,
      "size": 317,
      "vsize": 236,
      "weight": 941,
      "locktime": 0,
      "vin": [
        {
          "txid": "8619d1f5f3236bf42aa567994fc431c0906bfc8ba80d842aa568c2dd3563d6ec",
          "vout": 2,
          "scriptSig": {
            "asm": "",
            "hex": ""
          },
          "txinwitness": [
            "30440220605800a14d1237e281b5d888eaf24531ea431fc5c512e9672e2aca2222dc2e9e02206f8d757acef8a94b2a787c03fafd1f0fd92afbe08be3c450dab1137c104b843101",
            "026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea286"
          ],
          "sequence": 4294967293
        }
      ],
      "vout": [
        {
          "value": 0.00982110,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_HASH160 3970e94b1d2d9440b7b9316dd3cb66728a22860b OP_EQUAL",
            "hex": "a9143970e94b1d2d9440b7b9316dd3cb66728a22860b87",
            "address": "36vjhh9DY5jZhaKFpgPw9z6DSKXWLJXFJQ",
            "type": "scripthash"
          }
        },
        {
          "value": 0.00079070,
          "n": 1,
          "scriptPubKey": {
            "asm": "0 07154d960f9b7c044eb3b7e48a45b2ae5f58289f",
            "hex": "001407154d960f9b7c044eb3b7e48a45b2ae5f58289f",
            "address": "bc1qqu25m9s0nd7qgn4nkljg53dj4e04s2ylft0fyx",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 0.00843110,
          "n": 2,
          "scriptPubKey": {
            "asm": "0 d3e3389b2bbdcb50e4c2c826a95ed6d92e513d93",
            "hex": "0014d3e3389b2bbdcb50e4c2c826a95ed6d92e513d93",
            "address": "bc1q603n3xethh94pexzeqn2jhkkmyh9z0vnzx4ctw",
            "type": "witness_v0_keyhash"
          }
        },
        {
          "value": 0.00711090,
          "n": 3,
          "scriptPubKey": {
            "asm": "OP_HASH160 5149cd5ac5b95165994920f92e7bd9c9d597a94d OP_EQUAL",
            "hex": "a9145149cd5ac5b95165994920f92e7bd9c9d597a94d87",
            "address": "396q4wr3q6QDjMK3oGypoqK1Dsxezy9WHp",
            "type": "scripthash"
          }
        },
        {
          "value": 0.58401219,
          "n": 4,
          "scriptPubKey": {
            "asm": "0 f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "hex": "0014f60834ef165253c571b11ce9fa74e46692fc5ec1",
            "address": "bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf",
            "type": "witness_v0_keyhash"
          }
        }
      ],
      "fee": 0.00036567,
      "hex": "02000000000101ecd66335ddc268a52a840da88bfc6b90c031c44f9967a52af46b23f3f5d119860200000000fdffffff055efc0e000000000017a9143970e94b1d2d9440b7b9316dd3cb66728a22860b87de3401000000000016001407154d960f9b7c044eb3b7e48a45b2ae5f58289f66dd0c0000000000160014d3e3389b2bbdcb50e4c2c826a95ed6d92e513d93b2d90a000000000017a9145149cd5ac5b95165994920f92e7bd9c9d597a94d87c3217b0300000000160014f60834ef165253c571b11ce9fa74e46692fc5ec1024730440220605800a14d1237e281b5d888eaf24531ea431fc5c512e9672e2aca2222dc2e9e02206f8d757acef8a94b2a787c03fafd1f0fd92afbe08be3c450dab1137c104b84310121026e5628506ecd33242e5ceb5fdafe4d3066b5c0f159b3c05a621ef65f177ea28600000000"
    },
    {
      "txid": "af6c40234770c8e3fac9bfc14b5dc4ef59223407e8a24320233d3b89c36500c0",
      "hash": "af6c40234770c8e3fac9bfc14b5dc4ef59223407e8a24320233d3b89c36500c0",
      "version": 2,
      "size": 372,
      "vsize": 372,
      "weight": 1488,
      "locktime": 0,
      "vin": [
        {
          "txid": "5b8da0a71ca0a68782553e0bec7515a342490cea18c0913c7de710e66788c74a",
          "vout": 1,
          "scriptSig": {
            "asm": "30440220043697d59c9c7ca0cfc6f2bb64997b04c6ac6da104d0d0aec410f80fca448c91022059c21473dc079fac56fa90efec44c782513ad9cf5b0fe562dd55881c82bfc3ea[ALL] 03786af4b32017ec640dba2d2a7e1fd5aa4a231a658e4cbc114d51c031576e19bc",
            "hex": "4730440220043697d59c9c7ca0cfc6f2bb64997b04c6ac6da104d0d0aec410f80fca448c91022059c21473dc079fac56fa90efec44c782513ad9cf5b0fe562dd55881c82bfc3ea012103786af4b32017ec640dba2d2a7e1fd5aa4a231a658e4cbc114d51c031576e19bc"
          },
          "sequence": 4294967293
        },
        {
          "txid": "21973ecb9ed1dc2d656aee5451cbb49d93f63f4713da4ad5f0dd0d22119efe24",
          "vout": 1,
          "scriptSig": {
            "asm": "304402203ec8247ad3fce9936f2ce9b32f84b353df87acf9f66322bce5e62a62375961f002202c8f6d6b6b236d16078ebe1446f4e0359629491dd89eb5acdbcfad9395e58f4a[ALL] 03786af4b32017ec640dba2d2a7e1fd5aa4a231a658e4cbc114d51c031576e19bc",
            "hex": "47304402203ec8247ad3fce9936f2ce9b32f84b353df87acf9f66322bce5e62a62375961f002202c8f6d6b6b236d16078ebe1446f4e0359629491dd89eb5acdbcfad9395e58f4a012103786af4b32017ec640dba2d2a7e1fd5aa4a231a658e4cbc114d51c031576e19bc"
          },
          "sequence": 4294967293
        }
      ],
      "vout": [
        {
          "value": 5.73600000,
          "n": 0,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 8cf220cdf093afa35a7b3b689fe16050afc8c829 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a9148cf220cdf093afa35a7b3b689fe16050afc8c82988ac",
            "address": "1DrFfDSfUZMBP6YrSR4ug2mFgigfwfvETm",
            "type": "pubkeyhash"
          }
        },
        {
          "value": 45.68360097,
          "n": 1,
          "scriptPubKey": {
            "asm": "OP_DUP OP_HASH160 cebb2851a9c7cfe2582c12ecaf7f3ff4383d1dc0 OP_EQUALVERIFY OP_CHECKSIG",
            "hex": "76a914cebb2851a9c7cfe2582c12ecaf7f3ff4383d1dc088ac",
            "address": "1Kr6QSydW9bFQG1mXiPNNu6WpJGmUa9i1g",
            "type": "pubkeyhash"
          }
        }
      ],
      "fee": 0.00056417,
      "hex": "02000000024ac78867e610e77d3c91c018ea0c4942a31575ec0b3e558287a6a01ca7a08d5b010000006a4730440220043697d59c9c7ca0cfc6f2bb64997b04c6ac6da104d0d0aec410f80fca448c91022059c21473dc079fac56fa90efec44c782513ad9cf5b0fe562dd55881c82bfc3ea012103786af4b32017ec640dba2d2a7e1fd5aa4a231a658e4cbc114d51c031576e19bcfdffffff24fe9e11220dddf0d54ada13473ff6939db4cb5154ee6a652ddcd19ecb3e9721010000006a47304402203ec8247ad3fce9936f2ce9b32f84b353df87acf9f66322bce5e62a62375961f002202c8f6d6b6b236d16078ebe1446f4e0359629491dd89eb5acdbcfad9395e58f4a012103786af4b32017ec640dba2d2a7e1fd5aa4a231a658e4cbc114d51c031576e19bcfdffffff0200713022000000001976a9148cf220cdf093afa35a7b3b689fe16050afc8c82988aca1a44b10010000001976a914cebb2851a9c7cfe2582c12ecaf7f3ff4383d1dc088ac00000000"
    }
 ]
}

我想出了这个解决方案:

max=$(cat file | jq '[.tx[].vout[]] | max_by(.value) | .value')
cat file | jq '.tx[] | select(.vout[].value=='$max')

我会得到我想要的。但这让我觉得很愚蠢,所以请用一个简洁的解决方案来启发我。

lymnna71

lymnna711#

我已经想出了解决这个问题的办法
您的解决方案可以很容易地简化,只需调用一次jq。进一步的改进会导致:

.tx 
| ([.[].vout[].value]|max) as $max
| .[] | select(.vout[].value==$max)

但是,您可能希望避免重复:

.tx 
| ([.[].vout[].value]|max) as $max
|   .[] | select(any(.vout[]; .value == $max))

当然,上面会产生所有的最大值(即可能不止一个)。如果你想确保只得到第一个,你可以(例如)使用first

.tx 
| ([.[].vout[].value]|max) as $max
| first(.[] | select(any(.vout[]; .value == $max)))

或者简单地说:

.tx | max_by( [.vout[].value] | max)

相关问题