我怎樣才能從一個JSON檔案中輸出在另一個JSON檔案中不匹配的物件。例如,
file1:
[
{
"name"。"ABC"。
"年齡": "23",
"地址": "xyz".
},
{
"name": "DEF",
"年齡": "24",
"地址": "pqr".
}
]
file2:
[
{
"name"/span>: "ABC"。
"年齡": "23",
"地址": "xyz".
},
{
"name": "GHI",
"年齡": "24",
"地址": "pqr".
}
]
我想從檔案2中獲得與檔案1不匹配的輸出。例如:
輸出檔案:
[
{
"name"/span>。"GHI"。
"年齡": "24",
"地址": "pqr".
}
]
我想用Jq在shell腳本中做這件事。
uj5u.com熱心網友回復:
Jq的減法運算子正好能滿足你的需要。只要使用--slurpfile就可以把兩個檔案都變成變數:
jq -n --slurpfile file1 file1.json --slurpfile file2 file2.json '$file2[0] - $file1[0] '
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/309906.html
標籤:
上一篇:重定向一個管道鏈
下一篇:Shell腳本中的多行awk腳本
