mirror of
https://github.com/taigrr/yq
synced 2025-01-18 04:53:17 -08:00
Added File operators
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
```
|
||||
Reference in New Issue
Block a user