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

[question/feature-request] prune trailing whitespaces at read time #231

Open
jprobichaud opened this issue Jul 30, 2020 · 8 comments
Open

Comments

@jprobichaud
Copy link

Thanks for this great tool!

I've search to see if this was possible but couldn't find it. I have many csv files where the values are padded with whitespaces (from a db-extraction process). It is possible to read these files and remove from every columns (even headers) any trailing white spaces?

@BurntSushi
Copy link
Owner

Nope. xsv is mostly about slicing and dicing CSV data. I've mostly avoided taking the next step to data transformation tool, since that vastly increases its scope and complexity. It's plausible though that some special cases could be considered.

@jprobichaud
Copy link
Author

I see, this is understandable. Given how "simple" the interface is (each command does only one thing), I was seeing this as a simple flag to the "input" command or as new command called "transform" that would take simple transformations with a column selection options. Something like:

xsv transform [-s ColName1-ColName3 (same format as the xsv select syntax] [--tolower|toupper] [--ltrim|rtrim|trim (removing whitespaces to the left, to the right, on both side] [--format <printf_format>]

I can imagine a bunch of possible simple transformations (that wouldn't require performing calculations across a bunch of rows beforehand) that could be quite useful in general.

Output would go to stdout (or to a specified output file).

@Yomguithereal
Copy link
Contributor

@jprobichaud one tricky thing also to consider is the operation's order. The ones you show here won't be affected by the order you run them in (I think) but others may. Then CLI prompt & design issue can arise and decisions must be taken.

@jprobichaud
Copy link
Author

jprobichaud commented Jul 30, 2020 via email

@Yomguithereal
Copy link
Contributor

Another solution could be to have some kind of DSL such as:

xsv transform trim,lower

a flag to put the transformed value in a new column would be useful also. I use a custom python CLI tool to do what your command suggest already then I often pipe it into partition or search. But obviously my python counterpart is way slower than xsv (even if I can also do fancy things as evaluating python on cells and applying fuzzy matching functions such as phonetic encoding, stemmers and such).

@jprobichaud
Copy link
Author

jprobichaud commented Jul 31, 2020 via email

@Yomguithereal
Copy link
Contributor

Interesting, which python tool is that?

It's there but it is undocumented unfortunately.

A dsl could be useful to avoid
having to re-parse all the data too often, but that changes the philosophy
of the tool quite a bit!

I agree. But if such DSL is not more complex than splitting operations by comma I think we are not stretching too far.

@Yomguithereal
Copy link
Contributor

Yomguithereal commented Sep 23, 2020

@jprobichaud PR #242 can do what you need if this can help you. You can use it easily by installing xsv from my prod branch if required.

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

3 participants