Skip to content

Remove an element if some condition is met #2154

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

You must be logged in to vote

Sure, the issue is that you are first filtering to only include files with environment = production, and then deleting nodes in those matches.

Instead do:

yq 'del(select(.environment == "production") | .config.image)' examples/data1.yaml

The filtering is inside the delete, so it will only delete those matching nodes, or leave the data alone.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by L30Bola
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