mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-05 20:15:36 +00:00
Improving select docs
This commit is contained in:
parent
3793f723b8
commit
9bebbfffb7
@ -2,26 +2,6 @@
|
|||||||
|
|
||||||
Select is used to filter arrays and maps by a boolean expression.
|
Select is used to filter arrays and maps by a boolean expression.
|
||||||
|
|
||||||
## Select elements from array with regular expression
|
|
||||||
See more regular expression examples under the `string` operator docs.
|
|
||||||
|
|
||||||
Given a sample.yml file of:
|
|
||||||
```yaml
|
|
||||||
- this_0
|
|
||||||
- not_this
|
|
||||||
- nor_0_this
|
|
||||||
- thisTo_4
|
|
||||||
```
|
|
||||||
then
|
|
||||||
```bash
|
|
||||||
yq eval '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml
|
|
||||||
```
|
|
||||||
will output
|
|
||||||
```yaml
|
|
||||||
this_0
|
|
||||||
thisTo_4
|
|
||||||
```
|
|
||||||
|
|
||||||
## Select elements from array using wildcard prefix
|
## Select elements from array using wildcard prefix
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
@ -75,6 +55,26 @@ go
|
|||||||
going
|
going
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Select elements from array with regular expression
|
||||||
|
See more regular expression examples under the `string` operator docs.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
- this_0
|
||||||
|
- not_this
|
||||||
|
- nor_0_this
|
||||||
|
- thisTo_4
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq eval '.[] | select(test("[a-zA-Z]+_[0-9]$"))' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
this_0
|
||||||
|
thisTo_4
|
||||||
|
```
|
||||||
|
|
||||||
## Select items from a map
|
## Select items from a map
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
@ -92,7 +92,7 @@ cat
|
|||||||
dog
|
dog
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use select + with_entries to filter map keys
|
## Use select and with_entries to filter map keys
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
name: bob
|
name: bob
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user