关于利用shell将json数据解析后排序问题-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

关于利用shell将json数据解析后排序问题

2016-03-05 12:06:49 3586 1

最近在写一个模仿dropbox_uploader的百度网盘的shell脚本。通过调用pcs的api返回一个目录下的所有文件。返回的json数据如下:

{"list":[{"fs_id":1878243434,"path":"\/apps\/zjhui\/test","ctime":1392866001,"mtime":1392866001,"md5":"","size":0,"isdir":1},{"fs_id":3901347206,"path":"\/apps\/zjhui\/upload","ctime":1392860719,"mtime":1392860719,"md5":"","size":0,"isdir":1},{"fs_id":3190602252,"path":"\/apps\/zjhui\/aaaaaaaa","ctime":1392885465,"mtime":1392885465,"md5":"783b7e40cdfb4a1344d15b1f7081af66","size":35121,"isdir":0},{"fs_id":3734744594,"path":"\/apps\/zjhui\/baidu-pcs.txt","ctime":1390898949,"mtime":1390898949,"md5":"5ccce0498cf29996399750789f415bb8","size":450,"isdir":0},{"fs_id":4176732013,"path":"\/apps\/zjhui\/bash","ctime":1389845838,"mtime":1389845838,"md5":"286dc423e71186936c39e3507d2d0cf1","size":2076,"isdir":0},{"fs_id":1122970857,"path":"\/apps\/zjhui\/LICENSE","ctime":1391567032,"mtime":1391567032,"md5":"783b7e40cdfb4a1344d15b1f7081af66","size":35121,"isdir":0},{"fs_id":3086666598,"path":"\/apps\/zjhui\/LICENSE-0205","ctime":1391569592,"mtime":1391569592,"md5":"783b7e40cdfb4a1344d15b1f7081af66","size":35121,"isdir":0},{"fs_id":4120839796,"path":"\/apps\/zjhui\/LICENSE01","ctime":1391569447,"mtime":1391569447,"md5":"783b7e40cdfb4a1344d15b1f7081af66","size":35121,"isdir":0},{"fs_id":2922247596,"path":"\/apps\/zjhui\/Pcs.sh","ctime":1389857060,"mtime":1389857060,"md5":"aaeafb64fc4efcff24de3b4e92dc302f","size":3355,"isdir":0},{"fs_id":1874426057,"path":"\/apps\/zjhui\/Pcs_Uploader.sh","ctime":1389773672,"mtime":1389773672,"md5":"14d6e4f7b9daf7761a7f2aa83efaa64d","size":2653,"isdir":0},{"fs_id":2295037712,"path":"\/apps\/zjhui\/test1","ctime":1392869356,"mtime":1392869356,"md5":"5fceae3ba3777db47ed1cc6a9a96cf27","size":728,"isdir":0}],"request_id":4180656241}  

利用JSON.sh解析后如下:

["list",0,"fs_id"]  1878243434
["list",0,"path"]   "\/apps\/zjhui\/test"
["list",0,"ctime"]  1392866001
["list",0,"mtime"]  1392866001
["list",0,"md5"]    ""
["list",0,"size"]   0
["list",0,"isdir"]  1
["list",1,"fs_id"]  3901347206
["list",1,"path"]   "\/apps\/zjhui\/upload"
["list",1,"ctime"]  1392860719
["list",1,"mtime"]  1392860719
["list",1,"md5"]    ""
["list",1,"size"]   0
["list",1,"isdir"]  1
["list",2,"fs_id"]  3190602252
["list",2,"path"]   "\/apps\/zjhui\/aaaaaaaa"
["list",2,"ctime"]  1392885465
["list",2,"mtime"]  1392885465
["list",2,"md5"]    "783b7e40cdfb4a1344d15b1f7081af66"
["list",2,"size"]   35121
["list",2,"isdir"]  0
["list",3,"fs_id"]  3734744594
["list",3,"path"]   "\/apps\/zjhui\/baidu-pcs.txt"
["list",3,"ctime"]  1390898949
["list",3,"mtime"]  1390898949
["list",3,"md5"]    "5ccce0498cf29996399750789f415bb8"
["list",3,"size"]   450
["list",3,"isdir"]  0
["list",4,"fs_id"]  4176732013
["list",4,"path"]   "\/apps\/zjhui\/bash"
["list",4,"ctime"]  1389845838
["list",4,"mtime"]  1389845838
["list",4,"md5"]    "286dc423e71186936c39e3507d2d0cf1"
["list",4,"size"]   2076
["list",4,"isdir"]  0
["list",5,"fs_id"]  1122970857
["list",5,"path"]   "\/apps\/zjhui\/LICENSE"
["list",5,"ctime"]  1391567032
["list",5,"mtime"]  1391567032
["list",5,"md5"]    "783b7e40cdfb4a1344d15b1f7081af66"
["list",5,"size"]   35121
["list",5,"isdir"]  0
["list",6,"fs_id"]  3086666598
["list",6,"path"]   "\/apps\/zjhui\/LICENSE-0205"
["list",6,"ctime"]  1391569592
["list",6,"mtime"]  1391569592
["list",6,"md5"]    "783b7e40cdfb4a1344d15b1f7081af66"
["list",6,"size"]   35121
["list",6,"isdir"]  0
["list",7,"fs_id"]  4120839796
["list",7,"path"]   "\/apps\/zjhui\/LICENSE01"
["list",7,"ctime"]  1391569447
["list",7,"mtime"]  1391569447
["list",7,"md5"]    "783b7e40cdfb4a1344d15b1f7081af66"
["list",7,"size"]   35121
["list",7,"isdir"]  0
["list",8,"fs_id"]  2922247596
["list",8,"path"]   "\/apps\/zjhui\/Pcs.sh"
["list",8,"ctime"]  1389857060
["list",8,"mtime"]  1389857060
["list",8,"md5"]    "aaeafb64fc4efcff24de3b4e92dc302f"
["list",8,"size"]   3355
["list",8,"isdir"]  0
["list",9,"fs_id"]  1874426057
["list",9,"path"]   "\/apps\/zjhui\/Pcs_Uploader.sh"
["list",9,"ctime"]  1389773672
["list",9,"mtime"]  1389773672
["list",9,"md5"]    "14d6e4f7b9daf7761a7f2aa83efaa64d"
["list",9,"size"]   2653
["list",9,"isdir"]  0
["list",10,"fs_id"] 2295037712
["list",10,"path"]  "\/apps\/zjhui\/test1"
["list",10,"ctime"] 1392869356
["list",10,"mtime"] 1392869356
["list",10,"md5"]   "5fceae3ba3777db47ed1cc6a9a96cf27"
["list",10,"size"]  728
["list",10,"isdir"] 0
["request_id"]  1194090611  

我想通过解析这json数据,然后进行组装,最后得到类似于./dropbox.sh list的效果:

 [F] 35147   aaaaaaa
 [F] 9524791 Agile_Web_Development_with_Rails_4th_for_Rails_3.2.pdf
 [D] 0       Camera Uploads
 [D] 0       Photos
 [D] 0       Public
取消 提交回答
全部回答(1)
  • 爵霸
    2019-07-17 18:53:11
     cat data | jshon -e list -a -e isdir -u -p -e size -u -p -e path -u | sed 'N;N;s/^1/[D]/;s/^0/[F]/;s/\n/\t/g'
    [D]     0       /apps/zjhui/test
    [D]     0       /apps/zjhui/upload
    [F]     35121   /apps/zjhui/aaaaaaaa
    [F]     450     /apps/zjhui/baidu-pcs.txt
    [F]     2076    /apps/zjhui/bash
    [F]     35121   /apps/zjhui/LICENSE
    [F]     35121   /apps/zjhui/LICENSE-0205
    [F]     35121   /apps/zjhui/LICENSE01
    [F]     3355    /apps/zjhui/Pcs.sh
    [F]     2653    /apps/zjhui/Pcs_Uploader.sh
    [F]     728     /apps/zjhui/test1

    jshon 请自己安装。要排序自己按需求接 sort 命令。

    0 0
相关问答

1

回答

利用shell将json数据解析后排序问题

2016-06-17 16:56:40 2481浏览量 回答数 1

1

回答

新手,关于PHP操作JSON数据的问题。不胜感激!

2016-07-05 16:00:43 1723浏览量 回答数 1

1

回答

关于PHP操作JSON数据的问题!

2016-03-08 06:34:19 2246浏览量 回答数 1

0

回答

Spring MVC中,如何定义一个REST API返回Order订单的JSON数据的呀?

2021-11-09 20:44:50 218浏览量 回答数 0

1

回答

Spring MVC中,应该怎么定义一个REST API返回Order订单的JSON数据?

2021-11-02 20:55:41 355浏览量 回答数 1

1

回答

Jersey 返回json数据中日期格式 400 请求报错 

2020-05-30 21:08:37 385浏览量 回答数 1

1

回答

前台怎么返回json数据

2018-05-10 19:59:54 1235浏览量 回答数 1

1

回答

json数据怎么转成对象

2018-05-10 20:00:08 1369浏览量 回答数 1

1

回答

JSON数据传输后台拿不到,求大神指点

2016-07-06 19:37:38 1816浏览量 回答数 1

1

回答

json从后台读取数据大小写的问题

2016-07-05 09:05:12 1914浏览量 回答数 1
+关注
2
文章
9426
问答
问答排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载