比较两个json文件:shell脚本 [英] Comparing two json files : shell scripting

查看:167
本文介绍了比较两个json文件:shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较两个如下所示的json文件:

I would like to compare two json files which look like the following:

[
   {
      "type" : 1,
      "children" : {
         "nsubj" : {
            "role" : "topic",
            "POS" : [
               "noun"
            ]
         }
      },
      "role" : "vehicle",
      "POS" : [
         "noun"
      ]
   },

,另一个格式相似,但是两者之间存在一些差异,因为一个json文件由3336行组成,而另一个json由3724行组成.我想编写一个shell脚本,它将逐行比较这两个脚本,并且每当发现差异时,输出发生差异的行号.

and the other is in the similar format, but there are some differences between the two because one json file is made up of 3336 lines, while another is made up of 3724 lines. I would like to write a shell script which would compare the two line by line and whenever it finds a difference, output the line number where the difference occurred.

推荐答案

只需使用diff.喜欢

Just use diff. Like in

diff --unified file1.json file2.json

这篇关于比较两个json文件:shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆