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

csvsort: ascending sort for some columns, descending for others #931

Open
danmichaelo opened this issue Feb 8, 2018 · 4 comments
Open

Comments

@danmichaelo
Copy link

danmichaelo commented Feb 8, 2018

csvsort is great, but would be even better if you could combine ascending and descending sort. Columns prefixed with a minus sign could be sorted descending. Like so:

csvsort -c 1,2,-3

to sort by column 1 ascending, 2 ascending and 3 descending.

@donmullen
Copy link

Was just looking as csvkit and hit the same issue - need to order ascending on two columns - then descending on a third.

@jpmckinney jpmckinney added this to the 1.0.4 milestone May 21, 2018
@jpmckinney jpmckinney removed this from the Next version milestone Oct 17, 2023
@jpmckinney
Copy link
Member

We'd have to use functools.cmp_to_key as the basic key function can't switch order for different columns.

@jpmckinney
Copy link
Member

So a problem with specifying "-3" is that this is interpreted as "the range from the first column up to 3", same as the cut command. We can maybe use ~ if that seems intuitive.

@jpmckinney jpmckinney added this to the Priority milestone Feb 15, 2024
@Kjuly
Copy link

Kjuly commented Jun 24, 2024

As an option, we can use csvsql:

$ csvsql --query "SELECT * FROM YourFile ORDER BY C1 ASC, C2 ASC, C3 DESC" YourFile.csv

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

4 participants