Skip to content

Delete an item if another item in the same document meets a condition #1621

Answered by mikefarah
tukusejssirs asked this question in Q&A
Discussion options

You must be logged in to vote

Hi!

Here's the expression you need to run:

yq 'del(select(.metadata.name == "pear") | .spec.allow.logins[] | select(. == "four"))' file.yaml

It's very similar to what you had, but it first has select(.metadata.name == "pear") to select only the documents that have metadata.name == "pear" :)

To do two conditions, you can use "and", so for instance: select(.metadata.name == "pear" and .some.thing == "dog")

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tukusejssirs
Comment options

Answer selected by tukusejssirs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants