Split result array into files, but keep all parent keys? #2355
Answered
by
treatmesubj
treatmesubj
asked this question in
Q&A
-
I've got a yaml like below, with a bunch of templates, which I like to split into separate files, using a command like this: mkdir split &&
yq '.spec.templates.[]' my-pipeline.yaml -s '"./split/" + .templateName'`
apiVersion: crd.ibm.k8s.io/v1
kind: FactPipeline
metadata:
name: my-pipeline
spec:
templates:
- templateName: temp1
- templateName: temp2
- templateName: temp3 However, in each of the splits, it would be nice if I could keep all the parent-keys. apiVersion: crd.ibm.k8s.io/v1
kind: FactPipeline
metadata:
name: my-pipeline
spec:
templates:
- templateName: temp1 |
Beta Was this translation helpful? Give feedback.
Answered by
treatmesubj
Jun 2, 2025
Replies: 1 comment
-
both of these do what I wanted: mkdir split &&
yq '[.spec.templates.[] as $i | ($i | parent(3) | .spec.templates = [$i]) as $f | $f].[] | split_doc' \
my-pipeline.yaml \
-s '"./split/" + .spec.templates.[0].templateName'
mkdir split &&
yq '[.spec.templates.[] as $i | [$i | parent(3) | .spec.templates = [$i]].[0]].[] | split_doc' \
my-pipeline.yaml \
-s '"./split/" + .spec.templates.[0].templateName' |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
treatmesubj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
both of these do what I wanted: