【发布时间】:2015-03-17 18:21:07
【问题描述】:
我正在使用 jq (http://stedolan.github.io/jq/) 从一些 JSON 文件中提取一些特定数据并将其转换为另一个 JSON 文件,例如:
cat data1.json | ./jq '[.["messages"][] | {to: .to, from: .from, body: .body, direction: .direction, date_sent: .date_sent }]' > results1.json
我在一个目录中有 50 个 JSON 文件可以执行此操作。如何编写一些 shell 脚本来遍历所有 50 个文件、执行所述功能并保存到 50 个已清理的 JSON 文件?
我认为它是这样的,但需要一些指导:
for file in *.json | ./jq | '[.["messages"][] | {to: .to, from: .from, body: .body, direction: .direction, date_sent: .date_sent }]' "$file" "$newfile.json" ; done
谢谢!
【问题讨论】: