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

Introduce --sort: Sort by Header #95

Open
3 of 6 tasks
Dentrax opened this issue Oct 21, 2022 · 3 comments
Open
3 of 6 tasks

Introduce --sort: Sort by Header #95

Dentrax opened this issue Oct 21, 2022 · 3 comments

Comments

@Dentrax
Copy link

Dentrax commented Oct 21, 2022

Check list

  • I have read through the README
  • I have searched through the existing issues

Environment info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

Version

csview 1.2.2

Problem / Steps to reproduce

Thanks for such an awesome project! This is rock! 🔥

It would be nice to have a (--sort|--sort-by|--sort-asc|--sort-dsc) flag to sort items by providing header name: (I'm not sure about the flag namings)

"h1", "h2", "h3"
"ccc", "bbb", "aaa"
"bbb", "ccc", "bbb"
"aaa", "aaa", "ccc"

For example:

  • csview --sort-asc h1:
"h1", "h2", "h3"
"aaa", "aaa", "ccc"
"bbb", "ccc", "bbb"
"ccc", "bbb", "aaa"
  • csview --sort-dsc h2:
"h1", "h2", "h3"
"bbb", "ccc", "bbb"
"ccc", "bbb", "aaa"
"aaa", "aaa", "ccc"

WDYT?

@stale
Copy link

stale bot commented Apr 26, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 26, 2023
@Dentrax
Copy link
Author

Dentrax commented Apr 26, 2023

/remove-lifecycle stale

@stale stale bot removed the stale label Apr 26, 2023
@wfxr
Copy link
Owner

wfxr commented Jun 26, 2023

Hi @Dentrax, sorry for the late reply, and thanks for your suggestion. csview aims to be a pure, fast csv pager for cli. Data processing capabilities, such as filter, map, sort, aggregate, etc., can be well provided by tools such as xsv (suggest you take a look at this tool if you often need to deal with csv data). You can easily combine it with csview through pipes, which should be more in line with the unix style IMO:

$ cat a.csv
h1,h2,h3
ccc,bbb,aaa
bbb,ccc,bbb
aaa,aaa,ccc

$ cat a.csv | xsv sort -s h1
h1,h2,h3
aaa,aaa,ccc
bbb,ccc,bbb
ccc,bbb,aaa

$ cat a.csv | xsv sort -s h1 | csview
┌─────┬─────┬─────┐
│ h1  │ h2  │ h3  │
├─────┼─────┼─────┤
│ aaa │ aaa │ ccc │
│ bbb │ ccc │ bbb │
│ ccc │ bbb │ aaa │
└─────┴─────┴─────┘

$ cat a.csv | xsv sort -s h1 --reverse | xsv select h1,h3 | csview --number
┌───┬─────┬─────┐
│ # │ h1  │ h3  │
├───┼─────┼─────┤
│ 1 │ ccc │ aaa │
│ 2 │ bbb │ bbb │
│ 3 │ aaa │ ccc │
└───┴─────┴─────┘

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

No branches or pull requests

2 participants