-
-
Notifications
You must be signed in to change notification settings - Fork 602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort document by key #1024
Comments
This can now be done with 4.16.1 with the new yq ea '[.] | sort_by(.name) | .[] | splitDoc' file.yaml |
Initial commentThe suggestion doesn't seem to work:
My bad, |
Hello @mikefarah, sorry for bringing this thread back from the dead. But is it possible to have second (and third etc) key sorting like below. I.e. first sort all documents on X, but for if the value is the same, use the second key Y to sort within those? i.e. name: Beta
other: Epsilon
---
name: Alfa
other: Gamma
---
name: Beta
other: Delta result (Beta Delta comes before Beta Epsilon): name: Alfa
other: Gamma
---
name: Beta
other: Delta
---
name: Beta
other: Epsilon Thanks a lot 🙏 |
Not yet - but that would be good to add; feel free to raise a separate issue so I can track it :) |
Please describe your feature request.
I wish I could use yq to sort a multidocument file based on a key.
Describe the solution you'd like
Given a file
I would like to sort the order of the included yaml document given a key, so that the above, sorted by key
.name
would becomeThe text was updated successfully, but these errors were encountered: