Skip to content

How to remove a certian element in an array #1606

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

You must be logged in to vote

Easiest way to do it is to recursively search for that value and delete it - though this will delete other items matching that value:

yq  'del(.. | select(. == "gcc-or1k-elf"))' file.yaml

Otherwise, if you want to snipe it, then you have to put in the full path - which in this case is quite deep as there are a couple of arrays of maps:

yq eval 'del(.["build-packages"][] | select(has("on amd64")) | .[][] | select(. == "gcc-or1k-elf"))' file.yaml

Replies: 2 comments 2 replies

Comment options

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

Comment options

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

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