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

前端 未结 2 2309
[愿得一人]
[愿得一人] 2021-02-19 17:26

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

$ echo \'[\"a\",\"b\",\"c\",\"d\",\"e\"]\' | jq \'.[] | select(. == (\"a\",\"c\"))\'
2条回答
  •  隐瞒了意图╮
    2021-02-19 17:31

    I'm sure it is not the most simple solution, but it works :)

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

    Edit: one more solution - this is even worse :)

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

提交回复
热议问题