Given a yaml file, I want to select all fields which contain a key named "graph" and append those fields into another yaml file called result.yaml.
for example: Given a yaml file called myfile.yaml
services_list:
- name: service1
location: europe
graph: true
- name: service2
location: asia
- name: service3
location: asia
graph: true
and result.yaml:
services_list:
- name: my-service
location: europe
graph: true
The result.yaml should be:
services_list:
- name: my-service
location: europe
graph: true
- name: service1
location: europe
graph: true
- name: service3
location: asia
graph: true
Couldn't find a proper command for it, would appreciate your help here!
You can use
to write the
select()result to a temporary file.Then use
load()to read that file while updatingresult.yaml:This is probably possible in a single yq call tho