yq/mkdocs/prefix.md

76 lines
992 B
Markdown
Raw Normal View History

2018-11-18 15:35:28 +00:00
```
yq p <yaml_file> <path>
```
2020-01-13 05:58:11 +00:00
Prefixes a yaml document with the given path expression. The complete yaml content will be nested inside the new prefix path.
See docs for [path expression](path_expressions.md) for more details.
2018-11-18 15:35:28 +00:00
2020-01-13 05:58:11 +00:00
## Prefix a document
2018-11-18 15:35:28 +00:00
Given a data1.yaml file of:
```yaml
a:
b: [1, 2]
```
then
```bash
yq p data1.yaml c.d
```
will output:
```yaml
c:
d:
a:
b: [1, 2]
```
2020-01-13 05:58:11 +00:00
## Updating files in-place
2018-11-18 15:35:28 +00:00
```bash
yq p -i data1.yaml c
```
2020-01-13 05:58:11 +00:00
will update the data1.yaml file so that the path 'c' prefixes the document.
2018-11-18 15:35:28 +00:00
2020-01-13 05:58:11 +00:00
## Multiple Documents
### Prefix a single document
2018-11-18 15:35:28 +00:00
Given a data1.yaml file of:
```yaml
something: else
---
a: simple
b: cat
```
then
```bash
yq p -d1 data1.yaml c
```
will output:
```yaml
something: else
---
c:
a: simple
b: cat
```
2020-01-13 05:58:11 +00:00
### Prefix all documents
2018-11-18 15:35:28 +00:00
Given a data1.yaml file of:
```yaml
something: else
---
a: simple
b: cat
```
then
```bash
yq p -d'*' data1.yaml c
```
will output:
```yaml
c:
something: else
---
c:
a: simple
b: cat
```