0

列「usedsize」を数値の desc または asc で並べ替えたい。

入力:

{"name":"db1","tablespace":"TEMP","size":"1000","maxsize":"65536","usedsize":"21","status":0.03},
{"name":"db1","tablespace":"DAT","size":"360612","maxsize":"475680","usedsize":"360321","status":75.75},
{"name":"db1","tablespace":"CUNBDAT","size":"23800","maxsize":"131072","usedsize":"23694","status":18.08},

セパレーターと列の行を試してみましたが、何かがおかしいようです:

sort -t: -k10

期待されるビュー:

{"name":"db1","tablespace":"DAT","size":"360612","maxsize":"475680","usedsize":"360321","status":75.75},
{"name":"db1","tablespace":"CUNBDAT","size":"23800","maxsize":"131072","usedsize":"23694","status":18.08},
{"name":"db1","tablespace":"TEMP","size":"1000","maxsize":"65536","usedsize":"21","status":0.03},
4

2 に答える 2

1

あなたは言えた

sort -t, -k5,5r filename

入力を少し調整して有効な JSON にする場合は、次のように perl を使用できます。

perl -MJSON -00 -le '
    $data = decode_json(<>);
    print encode_json([sort {$b->{usedsize} <=> $a->{usedsize}} @$data]);
' <<END
[
{"name":"db1","tablespace":"TEMP","size":"1000","maxsize":"65536","usedsize":"21","status":0.03},
{"name":"db1","tablespace":"DAT","size":"360612","maxsize":"475680","usedsize":"360321","status":75.75},
{"name":"db1","tablespace":"CUNBDAT","size":"23800","maxsize":"131072","usedsize":"23694","status":18.08}
]
END

[{"status":75.75,"name":"db1","usedsize":"360321","maxsize":"475680","size":"360612","tablespace":"DAT"},{ "status":18.08,"name":"db1","usedsize":"23694","maxsize":"131072","size":"23800","tablespace":"CUNBDAT"},{"status ":0.03,"name":"db1","usedsize":"21","maxsize":"65536","size":"1000","tablespace":"TEMP"}]

于 2013-07-03T12:03:59.627 に答える