mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
42 lines
540 B
Markdown
42 lines
540 B
Markdown
|
# Select
|
||
|
|
||
|
Select is used to filter arrays and maps by a boolean expression.
|
||
|
|
||
|
## Select elements from array
|
||
|
Given a sample.yml file of:
|
||
|
```yaml
|
||
|
- cat
|
||
|
- goat
|
||
|
- dog
|
||
|
```
|
||
|
then
|
||
|
```bash
|
||
|
yq eval '.[] | select(. == "*at")' sample.yml
|
||
|
```
|
||
|
will output
|
||
|
```yaml
|
||
|
cat
|
||
|
goat
|
||
|
```
|
||
|
|
||
|
## Select and update matching values in map
|
||
|
Given a sample.yml file of:
|
||
|
```yaml
|
||
|
a:
|
||
|
things: cat
|
||
|
bob: goat
|
||
|
horse: dog
|
||
|
```
|
||
|
then
|
||
|
```bash
|
||
|
yq eval '(.a.[] | select(. == "*at")) |= "rabbit"' sample.yml
|
||
|
```
|
||
|
will output
|
||
|
```yaml
|
||
|
a:
|
||
|
things: rabbit
|
||
|
bob: rabbit
|
||
|
horse: dog
|
||
|
```
|
||
|
|