how to get the intersection of two JSON arrays using jq
问题 Given arrays X and Y (preferably both as inputs, but otherwise, with one as input and the other hardcoded), how can I use jq to output the array containing all elements common to both? e.g. what is a value of f such that echo '[1,2,3,4]' | jq 'f([2,4,6,8,10])' would output [2,4] ? I've tried the following: map(select(in([2,4,6,8,10]))) --> outputs [1,2,3,4] select(map(in([2,4,6,8,10]))) --> outputs [1,2,3,4,5] 回答1: A simple and quite fast (but somewhat naive) filter that probably does