Split a yaml file in to multiple files by key #1562
Replies: 2 comments
-
This was fun: yq '. as $d |
(.samples | keys | .[]) as $i ireduce([]; . +
[$d | {"samples": .samples | pick([$i]), "readunits": .readunits | pick($d | .samples[$i])} ])
| .[]' -s '(.samples | keys | .[0]) + ".yaml"' file.yaml Explanation:
To get the file names, we need an expression that runs against each output node, which is the single key entry under the samples map
|
Beta Was this translation helpful? Give feedback.
-
This is really awesome! Thank you for your prompt and detailed explanation. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to split a yaml file in to multiple files based on a key, the file names should be written with key name. The map arrays or not in order!
Appreciate any help! Thanks
Here's my input file
test.yaml
My expected output file names
WHH525.yaml
,WHH527.yaml
andWHH528.yaml
and outputs are...WHH525.yaml
WHH527.yaml
WHH528.yaml
Beta Was this translation helpful? Give feedback.
All reactions