使用Bash Shell处理JSON文件

本文通过一个测试用例,介绍了如何使用Bash Shell配合jq工具处理JSON数据。在数据管道系统和配置管理系统中,常常需要执行依赖于彼此的任务。文章提供了编写程序执行带有依赖关系的shell脚本的方法,并给出了JSON文件示例。每个任务有输入和输出文件,只有所有输入文件存在时任务才会执行,如果输出文件已存在,任务将被跳过。
摘要由CSDN通过智能技术生成

前言

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。本文提供一个真实的测试用例需求,设计逻辑类似Makefile,我以Bash处理JSON为例,Coding水平有限,请各位多多包涵哈,欢迎大家一起学习和挑战各种不同的语言来实现。

巧用jq处理JSON数据


更新历史

2015年06月19日 - 初稿

阅读原文 - http://wsgzao.github.io/post/bash-json/

扩展阅读


Test Case

In data pipeline system and configuration management systems, it’s very common that you need execute a bunch of jobs which has dependencies with each other.

Write a program pipeline_runner to execute a list of shell scripts. The definition of those scripts and their dependencies are described in a JSON file. The program only takes in one argument which is the file path of JSON file that defines the jobs.

For example,
// jobs.json

{
    "log0_compressed" : {
        "commands": "curl http://websrv0/logs/access.log.gz > access0.log.gz",
        "input": [],
        "output": "access0.log.gz"
    },
    "log0" : {
        "commands": "gunzip access0.log.gz",
        "input": ["access0.log.gz"],
        "output": "access0.log"
    },
    "log1_compressed": {
        "commands": "curl http://websrv1/logs/access.log.gz > access1.log.gz",
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值