yq/mkdocs/delete.md

87 lines
1.2 KiB
Markdown
Raw Normal View History

2018-05-07 06:06:33 +00:00
```
2020-01-13 05:58:11 +00:00
yq delete <yaml_file|-> <path_expression>
2018-05-07 06:06:33 +00:00
```
2020-01-13 05:58:11 +00:00
The delete command will delete all the matching nodes for the path expression in the given yaml input.
See docs for [path expression](path_expressions.md) for more details.
## Deleting from a simple document
2018-05-07 06:06:33 +00:00
Given a sample.yaml file of:
```yaml
b:
c: 2
apples: green
```
then
```bash
yq d sample.yaml b.c
```
2020-01-13 05:58:11 +00:00
will output
2018-05-07 06:06:33 +00:00
```yaml
b:
apples: green
```
2020-01-13 05:58:11 +00:00
## From STDIN
Use "-" (without quotes) in-place of a file name if you wish to pipe in input from STDIN.
2018-05-07 06:06:33 +00:00
```bash
2020-01-13 05:58:11 +00:00
cat sample.yaml | yq d - b.c
2018-05-07 06:06:33 +00:00
```
2020-01-13 05:58:11 +00:00
## Deleting in-place
2018-05-07 06:06:33 +00:00
```bash
yq d -i sample.yaml b.c
```
will update the sample.yaml file so that the 'c' node is deleted
2020-01-13 05:58:11 +00:00
## Multiple Documents
2019-05-14 06:05:25 +00:00
2020-01-13 05:58:11 +00:00
### Delete from single document
2018-06-20 03:42:00 +00:00
Given a sample.yaml file of:
```yaml
something: else
field: leaveMe
---
b:
c: 2
field: deleteMe
```
then
```bash
yq w -d1 sample.yaml field
```
will output:
```yaml
something: else
field: leaveMe
---
b:
c: 2
```
2020-01-13 05:58:11 +00:00
### Delete from all documents
2018-06-20 03:42:00 +00:00
Given a sample.yaml file of:
```yaml
something: else
field: deleteMe
---
b:
c: 2
field: deleteMeToo
```
then
```bash
yq w -d'*' sample.yaml field
```
will output:
```yaml
something: else
---
b:
c: 2
```