yq/mkdocs/read.md

69 lines
1.0 KiB
Markdown
Raw Normal View History

2017-04-13 05:36:59 +00:00
```
2020-01-13 05:58:11 +00:00
yq r <yaml_file|json_file> <path_expression>
2017-04-13 05:36:59 +00:00
```
2020-01-13 05:58:11 +00:00
TALK PRINTING ABOUT KEYS AND VALUES
2020-01-13 05:58:11 +00:00
Returns the matching nodes of the path expression for the given yaml file (or STDIN).
See docs for [path expression](path_expressions.md) for more details.
## Basic
2017-04-13 05:36:59 +00:00
Given a sample.yaml file of:
```yaml
b:
c: 2
```
then
```bash
2017-12-17 22:11:08 +00:00
yq r sample.yaml b.c
2017-04-13 05:36:59 +00:00
```
will output the value of '2'.
2020-01-13 05:58:11 +00:00
## From Stdin
2017-04-13 05:36:59 +00:00
Given a sample.yaml file of:
```bash
2017-12-17 22:11:08 +00:00
cat sample.yaml | yq r - b.c
2017-04-13 05:36:59 +00:00
```
will output the value of '2'.
2020-01-13 05:58:11 +00:00
## Multiple Documents
### Reading from a single document
2018-06-20 03:42:00 +00:00
Given a sample.yaml file of:
```yaml
something: else
---
b:
c: 2
```
then
```bash
yq r -d1 sample.yaml b.c
```
will output the value of '2'.
2020-01-13 05:58:11 +00:00
### Read from all documents
2018-07-08 11:53:38 +00:00
Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired.
Given a sample.yaml file of:
```yaml
name: Fred
age: 22
---
name: Stella
age: 23
---
name: Android
age: 232
```
then
```bash
yq r -d'*' sample.yaml name
```
will output:
```
- Fred
- Stella
- Android
2020-01-13 05:58:11 +00:00
```