-
Notifications
You must be signed in to change notification settings - Fork 327
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
Allow columns to be selected using regular expressions #157
base: master
Are you sure you want to change the base?
Conversation
This allows a selector such as r'a[bc]?' to be used, which would select columns 'a', 'ab', 'ac' but not 'ad'. This can be used in the 'xsv select' command as well as anywhere that the '--select' flag appears.
BTW I'm not super happy with the user interface here - would happily receive tips on how to implement regex matching as a flag. |
I think detecting the regex syntax instead of a flag is a reasonable approach, rather than introducing a new flag for each of the subcommands that use May I suggest the regex syntax used in awk,sed? i.e. |
@mintyplanet Yes, I think I prefer that syntax too. I've pushed a new commit switching to that instead. |
I'd like to extend this idea to having replacement capability. Basically a sort of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to update the usage text in src/cmd/select.rs
to describe regex selectors.
Thanks for the review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me!
Please update the usage documentation in |
@CMCDragonkai Your idea seems sufficiently different from this PR that I would recommend you create a new Issue. If you could provide an example with inputs, outputs and hypothetical xsv command/flag, that would be helpful. |
Let me know if you'd like this rebasing 👍 |
@mintyplanet @BurntSushi is this mergeable, in your eyes? If not, what changes would you like to see first? Thanks! |
Looks good to me, but I don't have commit rights. |
This is fantastic -- just what I was looking for. Is there anything we can do to help get this merged in? |
This allows a selector such as r'a[bc]?' to be used, which would
select columns 'a', 'ab', 'ac' but not 'ad'. This can be used in
the 'xsv select' command as well as anywhere that the '--select' flag
appears.
The interface is different to the one discussed in #155 because I couldn't think of an easy way to include the regex flag when
deserialize
ing theSelectColumns
. It matches the regular expression string syntax from Python at the minute (i.e. prefixing a string withr
), but it's a little ugly on the shell due to the need for two sets of strings :(Here's some examples: