Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 608

how to use jq to filter select items not in list?

$
0
0

In jq, I can select an item in a list fairly easily:

$ echo '["a","b","c","d","e"]' | jq '.[] | select(. == ("a","c"))'

Or if you prefer to get it as an array:

$ echo '["a","b","c","d","e"]' | jq 'map(select(. == ("a","c")))'

But how do I select all of the items that are not in the list? Certainly . != ("a","c") does not work:

$ echo '["a","b","c","d","e"]' | jq 'map(select(. != ("a","c")))'["a","b","b","c","d","d","e","e"]

The above gives every item twice, except for "a" and "c"

Same for:

$ echo '["a","b","c","d","e"]' | jq '.[] | select(. != ("a","c"))'"a""b""b""c""d""d""e""e"

How do I filter out the matching items?


Viewing all articles
Browse latest Browse all 608

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>