shell数组的差集

https://stackoverflow.com/questions/29396154/jq-setdiff-of-two-arrays

1.

echo -n '{"all":["A","B","C","ABC"],"some":["B","C"]}' | jq '. as $d | .all | del(.[ indices($d.some[])[] ])'

2.

array1='["A","B","C","ABC"]'
array2='["B","C"]'

jq -n --argjson array1 "$array1" --argjson array2 "$array2" '$array1-$array2'

jq -n --argjson array1 "$array1" --argjson array2 "$array2" 
'{"all": $array1,"some":$array2} | .all-.some'

3.

echo -n '{"all":["A","B","C","ABC"],"some":["B","C"]}' | jq '  . as $d
| .all
| [indices($d.some[])[]] as $found
| del(.[ $found[] ])
| "all", $d.all, "some", $d.some, "removing indices", $found, "result", .‘

 

https://github.com/jqlang/jq/issues/563

https://stackoverflow.com/questions/45456414/convert-json-lines-to-json-array-using-jq

 

posted @ 2023-06-12 19:54  lvmxh  阅读(115)  评论(0编辑  收藏  举报