Skip to content

How to remove an item of an array #1340

Answered by mikefarah
Evantage-WS asked this question in Q&A

You must be logged in to vote

Yep:

yq 'del(.options.k3s.extraArgs[] | select(.arg == "--flannel-backend=none"))' file.yaml

Explanation:

  • .options.k3s.extraArgs[] will match every item under extraArgs
  • select(.arg == "--flannel-backend=none") filters the items to only include the ones that have the matching arg value
  • wrap the whole thing in del to delete those matching items

Replies: 2 comments 1 reply

You must be logged in to vote
1 reply
@mikefarah

Answer selected by Evantage-WS

You must be logged in to vote
0 replies
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