1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Added File operators

This commit is contained in:
Mike Farah
2020-11-20 23:08:12 +11:00
parent d38caf6bc2
commit e451119014
4 changed files with 8 additions and 10 deletions

View File

@@ -1,13 +1,13 @@
The file operator is used to filter based on filename. This is most often used with merge when needing to merge specific files together.
File operators are most often used with merge when needing to merge specific files together. Note that when doing this, you will need to use `eval-all` to ensure all yaml documents are loaded into memory before performing the merge (as opposed to `eval` which runs the expression once per document).
```bash
yq eval 'filename == "file1.yaml" * fileIndex == 0' file1.yaml file2.yaml
yq eval-all 'select(fileIndex == 0) * select(filename == "file2.yaml")' file1.yaml file2.yaml
```
## Examples
### Get filename
Given a sample.yml file of:
```yaml
'': null
a: cat
```
then
```bash
@@ -21,7 +21,7 @@ sample.yaml
### Get file index
Given a sample.yml file of:
```yaml
'': null
a: cat
```
then
```bash

View File

@@ -1,5 +1,5 @@
The file operator is used to filter based on filename. This is most often used with merge when needing to merge specific files together.
File operators are most often used with merge when needing to merge specific files together. Note that when doing this, you will need to use `eval-all` to ensure all yaml documents are loaded into memory before performing the merge (as opposed to `eval` which runs the expression once per document).
```bash
yq eval 'filename == "file1.yaml" * fileIndex == 0' file1.yaml file2.yaml
yq eval-all 'select(fileIndex == 0) * select(filename == "file2.yaml")' file1.yaml file2.yaml
```