{"id":126161,"date":"2020-01-16T21:30:21","date_gmt":"2020-01-16T13:30:21","guid":{"rendered":"http:\/\/4563.org\/?p=126161"},"modified":"2020-01-16T21:30:21","modified_gmt":"2020-01-16T13:30:21","slug":"%e8%af%b7%e6%95%99%e4%b8%80%e4%b8%8b%e4%bc%9a-shell-%e5%a4%84%e7%90%86-json-%e8%84%9a%e6%9c%ac%e7%9a%84%e5%a4%a7%e4%bd%ac","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=126161","title":{"rendered":"\u8bf7\u6559\u4e00\u4e0b\u4f1a shell \u5904\u7406 JSON \u811a\u672c\u7684\u5927\u4f6c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559\u4e00\u4e0b\u4f1a shell \u5904\u7406 JSON \u811a\u672c\u7684\u5927\u4f6c               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : toyst <\/span>  <span><i><\/i> 78<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u903b\u8f91\u662f\u8fd9\u6837\u7684\uff0c\u6211\u60f3\u5224\u65ad\u6bcf\u6bb5 <code>num_leechs<\/code> \u7684\u503c\uff0c\u5982\u679c\u5927\u4e8e 10\uff0c\u5c31\u8fd4\u56de <code>name<\/code> \u548c <code>hash<\/code> \u7684\u503c\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code>[{         \"added_on\": 1576120104,         \"hash\": \"2fcb75646c688975daa840dfe466d21bc64118de\",         \"name\": \"Ad.Astra.2019\",         \"num_leechs\": 545     },  {         \"added_on\": 1576120104,         \"hash\": \"5c04a056d6821792db902b22aesdf23r2cd23rd23\",         \"name\": \"ABC\",         \"num_leechs\": 32     }, {         \"added_on\": 1576120104,         \"hash\": \"dfgsdfg34tv34tg34g34g6547h547h4567g567h45\",         \"name\": \"eGE\",         \"num_leechs\": 2     } ]  <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>13<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"67605\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : noqwerty <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 jq \u5e94\u8be5\u53ef\u4ee5\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67606\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mcfog <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             jq \u8f7b\u677e\u641e\u5b9a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67607\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7528 py \u6216\u8005 perl import json \u6bd4\u8f83\u5bb9\u6613                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67608\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wamson <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Python \u5927\u6cd5\u597d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67609\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : renmu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             [{\u201dhash\u201d:row[hash], \u201dname\u201d:row[name]]} for row in data if data[num_leechs&gt;10]] \u8fd9\u662f py \u5199\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67610\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ddsfeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u56e0\u4e3a\u4e0d\u786e\u5b9a\u4f60\u8bf4\u7684 &#8216;\u5c31\u8fd4\u56de name \u548c hash \u7684\u503c&#8217;, \u662f\u54ea\u79cd\u683c\u5f0f\u7684, \u6240\u4ee5\u5f04\u4e86\u4e24\u4e2a, \u81ea\u884c\u9009\u62e9..<\/p>\n<p>jq &#8211;&gt; stedolan.github.io\/jq\/manual\/<\/p>\n<p>1.json \u4e3a\u4f60\u5e16\u7684\u5185\u5bb9<\/p>\n<p>&#8220;`<br \/>$ cat 1.json | jq &#8216;[.[] | select(.num_leechs &gt; 10) | {name,hash}]&#8217;<br \/>[<br \/> {<br \/> &#8220;name&#8221;: &#8220;Ad.Astra.2019&#8221;,<br \/> &#8220;hash&#8221;: &#8220;2fcb75646c688975daa840dfe466d21bc64118de&#8221;<br \/> },<br \/> {<br \/> &#8220;name&#8221;: &#8220;ABC&#8221;,<br \/> &#8220;hash&#8221;: &#8220;5c04a056d6821792db902b22aesdf23r2cd23rd23&#8221;<br \/> }<br \/>]<br \/>&#8220;`<\/p>\n<p>&#8220;`<br \/>$ cat 1.json | jq &#8216;[.[] | select(.num_leechs &gt; 10) | [.name,.hash]]&#8217;<br \/>[<br \/> [<br \/> &#8220;Ad.Astra.2019&#8221;,<br \/> &#8220;2fcb75646c688975daa840dfe466d21bc64118de&#8221;<br \/> ],<br \/> [<br \/> &#8220;ABC&#8221;,<br \/> &#8220;5c04a056d6821792db902b22aesdf23r2cd23rd23&#8221;<br \/> ]<br \/>]<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67611\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : toyst <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ddsfeng \u4f60\u597d\uff0c\u518d\u8bf7\u6559\u4e00\u4e0b\u8fd4\u56de`name=xxx,hash=xxx`\u8fd9\u79cd\u5e94\u8be5\u600e\u4e48\u5199\u5462\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67612\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : opticaline <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             cat temp | grep num_leechs -B 2 | awk -v RS=&#8221;&#8211;&#8221; &#8216;{if($6 &gt; 10){print $4,$2}}&#8217; | awk -F &#8216;[&#8220;, ]&#8217; &#8216;{print &#8220;name=&#8221;$2&#8221;,hash=&#8221;$6}&#8217;<\/p>\n<p>name=Ad.Astra.2019,hash=2fcb75646c688975daa840dfe466d21bc64118de<br \/>name=ABC,hash=5c04a056d6821792db902b22aesdf23r2cd23rd23                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67613\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : geelaw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6700\u7b80\u5355\u4e14\u53ef\u7ef4\u62a4\u7684\u4e4b\u4e00\u662f\u7528 PowerShell<\/p>\n<p>Get-Content | ConvertFrom-Json | Write-Output | Where-Object num_leechs -gt 10 | Select-Object name, hash                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67614\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Tink <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             jq                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67615\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ddsfeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @toyst \u4f60\u80fd\u4e00\u6b21\u6027\u8bf4\u5b8c\u5417? \u628a\u4f60\u6700\u7ec8\u60f3\u8981\u7684\u7ed3\u679c, \u5b8c\u6574\u7684\u53d1\u51fa\u6765.<\/p>\n<p>\u4f60\u73b0\u5728\u8fd9\u4e2a, \u4f9d\u7136\u8bf4\u7684\u662f\u5355\u4e2a\u7684, \u4f60\u7684\u7ed3\u679c\u91cc\u9762\u6709\u591a\u4e2a, \u662f\u8fd4\u56de\u6570\u7ec4\u5417?<\/p>\n<p>\u591a\u4e2a\u7684\u65f6\u5019\u8fd9\u6837\u5417???<\/p>\n<p>$ cat 1.json | jq &#8216;[.[] | select(.num_leechs &gt; 10) | @text &#8220;name=(.name),hash=(.hash)&#8221;]&#8217;<br \/>[<br \/> &#8220;name=Ad.Astra.2019,hash=2fcb75646c688975daa840dfe466d21bc64118de&#8221;,<br \/> &#8220;name=ABC,hash=5c04a056d6821792db902b22aesdf23r2cd23rd23&#8221;<br \/>]                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67616\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ddsfeng <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @toyst \u8fd8\u662f\u8bf4\u662f\u8fd9\u6837????<\/p>\n<p>$ cat 1.json | jq &#8216;.[] | select(.num_leechs &gt; 10) | @text &#8220;name=(.name),hash=(.hash)&#8221;&#8216;<br \/>&#8220;name=Ad.Astra.2019,hash=2fcb75646c688975daa840dfe466d21bc64118de&#8221;<br \/>&#8220;name=ABC,hash=5c04a056d6821792db902b22aesdf23r2cd23rd23&#8221;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"67617\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ETiV <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             jq<br \/>\u81ea\u5df1\u591a\u770b\u770b\u6587\u6863\uff0c\u4f60\u5c31\u80fd\u4e0d\u6c42\u4eba\u4e86\uff08\u6216\u8005\u53ef\u4ee5\u5e2e\u52a9\u522b\u4eba\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559\u4e00\u4e0b\u4f1a shell \u5904\u7406 JS&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/126161"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=126161"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/126161\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=126161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=126161"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=126161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}