mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Fixed empty array op
This commit is contained in:
@@ -100,7 +100,7 @@ a:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a[] | select(. == "apple") |= "frog"' sample.yml
|
||||
yq eval '.a.[] | select(. == "apple") |= "frog"' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
||||
@@ -10,6 +10,7 @@ yq eval --null-input '[]'
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
[]
|
||||
```
|
||||
|
||||
## Collect single
|
||||
|
||||
@@ -34,7 +34,7 @@ pets:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '{.name: .pets[]}' sample.yml
|
||||
yq eval '{.name: .pets.[]}' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@@ -57,7 +57,7 @@ pets:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '{.name: .pets[]}' sample.yml
|
||||
yq eval '{.name: .pets.[]}' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
## Retrieve a document index
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: cat
|
||||
---
|
||||
a: frog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a | documentIndex' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
0
|
||||
---
|
||||
1
|
||||
```
|
||||
|
||||
## Filter by document index
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: cat
|
||||
---
|
||||
a: frog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'select(. | documentIndex == 1)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
a: frog
|
||||
```
|
||||
|
||||
## Print Document Index with matches
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
a: cat
|
||||
---
|
||||
a: frog
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '.a | ({"match": ., "doc": (. | documentIndex)})' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
match: cat
|
||||
doc: 0
|
||||
match: frog
|
||||
doc: 1
|
||||
```
|
||||
|
||||
@@ -26,7 +26,7 @@ a:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval '(.a[] | select(. == "*at")) |= "rabbit"' sample.yml
|
||||
yq eval '(.a.[] | select(. == "*at")) |= "rabbit"' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
||||
Reference in New Issue
Block a user