惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
月光博客
月光博客
雷峰网
雷峰网
WordPress大学
WordPress大学
博客园 - 司徒正美
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
H
Help Net Security
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security @ Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
爱范儿
爱范儿
W
WeLiveSecurity
J
Java Code Geeks
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
T
Threatpost
The Cloudflare Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
N
Netflix TechBlog - Medium
Latest news
Latest news
V2EX - 技术
V2EX - 技术
小众软件
小众软件
T
The Blog of Author Tim Ferriss
A
Arctic Wolf
B
Blog RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
C
Check Point Blog
N
News | PayPal Newsroom
Cyberwarzone
Cyberwarzone
V
V2EX
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
Microsoft Security Blog
Microsoft Security Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
DataBreaches.Net
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
K
Kaspersky official blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com

NickChenyx's Blog

Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish Create_Rubbish
Create_Rubbish
nickChen · 2018-04-18 · via NickChenyx's Blog

本地文件处理工作流整理,待归档到一个合适的目录

通过 dsq join 文件条件查找

安装工具

// 文件 a.json
[
    {"type": "tool", "id": "1"},
    {"type": "tool", "id": "2"},
    {"type": "tool", "id": "3"},
    {"type": "book", "id": "1"},
    {"type": "none", "id": "1"}
]
// 文件 b.json
[
    {"author": "nickchen", "type":"tool", "tag":[1,2,3]},
    {"author": "whoru", "type":"none"},
    {"author": "teacher", "type":"book"}
]

需求打印出 author、type、id ,且 id=1 的组合

  1. 因为 dsq 没法解析内嵌列表,所有 b.json 中的 tag 字段必须要被删除
  2. 需要 dsq join a.json 和 b.json,且判断 id = 1
  3. 打印结果确认是否符合要求
  4. 输出一个格式化的 json array

开始执行:

  1. 清理 b.json 中的 tag 字段
    • jq 的最外侧 [] 是列表构造器,会生成一份列表
    • jq 的 .[] 代表迭代器,迭代当前这个 json array
    • jq 的 | 是 pipe 管道,将数据流转到下一个程序
    • jq 的 del() 是内建函数,可以删除某个字段
➜  cat b.json | jq '[.[]|del(.tag)]' > c.json
or
➜  cat b.json | jq '[.[]|{author:.author,type:.type}]' > c.json
  1. dsq join 查询 & 打印结果
    • dsq 的 --pretty 可以输出表格结果
    • dsq 输入多个文件,可以按照进行 join 操作,表名即文件顺序
➜  dsq --pretty a.json c.json "select {0}.id, {1}.type, {1}.author from {0} join {1} on {0}.type = {1}.type where {0}.id = 1"
+----------+----+------+
|  author  | id | type |
+----------+----+------+
| nickchen |  1 | tool |
| teacher  |  1 | book |
| whoru    |  1 | none |
+----------+----+------+
  1. 输出一个格式化的 json array
➜  dsq a.json c.json "select {0}.id, {1}.type, {1}.author from {0} join {1} on {0}.type = {1}.type where {0}.id = 1" | jq .
[
  {
    "id": "1",
    "type": "tool",
    "author": "nickchen"
  },
  {
    "type": "book",
    "author": "teacher",
    "id": "1"
  },
  {
    "id": "1",
    "type": "none",
    "author": "whoru"
  }
]

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 nickchenyx@gmail.com