How to remove a certian element in an array #1606
-
Hi, I am quite new to yq, and I have tried to google and search the discussions here for a while, still not able to get the expected ressult Here is the build-packages:
- bc
- bison
- build-essential
- on amd64:
- gcc-aarch64-linux-gnu
- gcc-or1k-elf I would like to remove the build-packages:
- bc
- bison
- build-essential
- on amd64:
- gcc-aarch64-linux-gnu Thanks in advance for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Have you tried something like this ?
|
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
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: