Skip to content

Sort YAML docs in file by key #1101

Answered by mikefarah
mamachanko asked this question in Q&A
Discussion options

You must be logged in to vote

You can combine the documents into a single array, sort, then split back out into separate docs again. Because we want to process all the documents together (rather than one at a time), well need to use eval-all/ea:

yq ea '[.] | sort_by(.name) | .[] | splitDoc' file.yml

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mamachanko
Comment options

Answer selected by mamachanko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants