2024-03-23 23:59:29 +00:00
|
|
|
# Omit
|
|
|
|
|
|
|
|
Works like `pick`, but instead you specify the keys/indices that you _don't_ want included.
|
2024-03-23 06:15:45 +00:00
|
|
|
|
|
|
|
## Omit keys from map
|
2024-03-23 23:59:29 +00:00
|
|
|
Note that non existent keys are skipped.
|
2024-03-23 06:15:45 +00:00
|
|
|
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
myMap:
|
|
|
|
cat: meow
|
|
|
|
dog: bark
|
|
|
|
thing: hamster
|
|
|
|
hamster: squeak
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yq '.myMap |= omit(["hamster", "cat", "goat"])' sample.yml
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
myMap:
|
|
|
|
dog: bark
|
|
|
|
thing: hamster
|
|
|
|
```
|
|
|
|
|
|
|
|
## Omit indices from array
|
2024-03-23 23:59:29 +00:00
|
|
|
Note that non existent indices are skipped.
|
2024-03-23 06:15:45 +00:00
|
|
|
|
|
|
|
Given a sample.yml file of:
|
|
|
|
```yaml
|
|
|
|
- cat
|
|
|
|
- leopard
|
|
|
|
- lion
|
|
|
|
```
|
|
|
|
then
|
|
|
|
```bash
|
|
|
|
yq 'omit([2, 0, 734, -5])' sample.yml
|
|
|
|
```
|
|
|
|
will output
|
|
|
|
```yaml
|
|
|
|
- leopard
|
|
|
|
```
|
|
|
|
|