yq/pkg/yqlib/doc/Delete Operator.md

51 lines
532 B
Markdown
Raw Normal View History

2020-11-17 22:44:16 +00:00
Deletes matching entries in maps or arrays.
## Examples
### Delete entry in map
Given a sample.yml file of:
```yaml
a: cat
b: dog
```
then
```bash
yq eval 'del(.b)' sample.yml
```
will output
```yaml
2020-11-19 05:45:05 +00:00
a: cat
2020-11-17 22:44:16 +00:00
```
### Delete entry in array
Given a sample.yml file of:
```yaml
- 1
- 2
- 3
```
then
```bash
yq eval 'del(.[1])' sample.yml
```
will output
```yaml
2020-11-19 05:45:05 +00:00
- 1
- 3
2020-11-17 22:44:16 +00:00
```
### Delete no matches
Given a sample.yml file of:
```yaml
a: cat
b: dog
```
then
```bash
yq eval 'del(.c)' sample.yml
```
will output
```yaml
2020-11-19 05:45:05 +00:00
a: cat
b: dog
2020-11-17 22:44:16 +00:00
```