gkumar7 gkumar7 - 2 months ago 18
Bash Question

Comparing two json files : shell scripting

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"
]
},


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.

Answer

Just use diff. Like in

diff --unified file1.json file2.json