























本地文件处理工作流整理,待归档到一个合适的目录
安装工具
brew install dsq, dsq githubbrew install jq, jq github// 文件 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 的组合
开始执行:
[] 是列表构造器,会生成一份列表.[] 代表迭代器,迭代当前这个 json array| 是 pipe 管道,将数据流转到下一个程序del() 是内建函数,可以删除某个字段➜ cat b.json | jq '[.[]|del(.tag)]' > c.json
or
➜ cat b.json | jq '[.[]|{author:.author,type:.type}]' > c.json
--pretty 可以输出表格结果➜ 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 |
+----------+----+------+
➜ 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
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。