There is documentation explaining how to sort an array using yq https://mikefarah.gitbook.io/yq/operators/sort
But it'd like to shuffle (random sorting)
Given an example
i'd like to sort it randomly yq 'sort_by(RANDOM)' sample.yml
Any ideas?
I'd tried the examples in the official documentation https://mikefarah.gitbook.io/yq/operators/sort
Unfortunally, yq does not provide a shuffle command.
A workaround, until your github issue is being worked on, could by to use the bash build-in shuf
:
yq
's output piped to shuf
yq
's env
to insert the bash variable into the desired placeexport shuffled=$(yq e '.MyData' input | shuf)
yq e '.MyData |= env(shuffled)' input
Will output a pesuedo random order of the MyData
array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.