yq/pkg/yqlib/doc/Boolean Operators.md

45 lines
667 B
Markdown
Raw Normal View History

2020-11-20 03:35:34 +00:00
The `or` and `and` operators take two parameters and return a boolean result. These are most commonly used with the `select` operator to filter particular nodes.
## Examples
2020-11-20 04:31:49 +00:00
### OR example
Running
2020-11-20 03:35:34 +00:00
```bash
2020-11-20 04:31:49 +00:00
yq eval --null-input 'true or false'
2020-11-20 03:35:34 +00:00
```
will output
```yaml
2020-11-20 04:31:49 +00:00
true
2020-11-20 03:35:34 +00:00
```
2020-11-20 04:31:49 +00:00
### AND example
Running
2020-11-20 03:35:34 +00:00
```bash
2020-11-20 04:31:49 +00:00
yq eval --null-input 'true and false'
2020-11-20 03:35:34 +00:00
```
will output
```yaml
2020-11-20 04:31:49 +00:00
false
2020-11-20 03:35:34 +00:00
```
2020-11-20 04:31:49 +00:00
### Matching nodes with select, equals and or
2020-11-20 03:35:34 +00:00
Given a sample.yml file of:
```yaml
2020-11-20 04:31:49 +00:00
- a: bird
b: dog
- a: frog
b: bird
- a: cat
b: fly
2020-11-20 03:35:34 +00:00
```
then
```bash
2020-11-20 04:33:21 +00:00
yq eval '[.[] | select(.a == "cat" or .b == "dog")]' sample.yml
2020-11-20 03:35:34 +00:00
```
will output
```yaml
2020-11-20 04:33:21 +00:00
- a: bird
b: dog
- a: cat
b: fly
2020-11-20 03:35:34 +00:00
```