Skip to content
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_by() to support multiple prioritized keys #1541

Closed
eripa opened this issue Feb 2, 2023 · 2 comments
Closed

sort_by() to support multiple prioritized keys #1541

eripa opened this issue Feb 2, 2023 · 2 comments

Comments

@eripa
Copy link

eripa commented Feb 2, 2023

Please describe your feature request.

It would be great to have way to impose second, third etc sorting order. See the below example. 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.

Related to #1024

#1024 (comment)

Describe the solution you'd like
If we have file.yml like:

name: Beta
other: Epsilon
---
name: Alfa
other: Gamma
---
name: Beta
other: Delta

And we run a command:

yq ea '[.] | sort_by(.name, .other) | .[] | splitDoc' file.yaml

it could output

name: Alfa
other: Gamma
---
name: Beta
other: Delta
---
name: Beta
other: Epsilon

Describe alternatives you've considered
Have not tried any other solutions. As far as I know this isn't supported, see: #1024 (comment)

@mikefarah
Copy link
Owner

Fixed in v4.31.1, see https://mikefarah.gitbook.io/yq/operators/sort#sort-by-multiple-fields

@eripa
Copy link
Author

eripa commented Feb 20, 2023

This is awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants