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

Field ranges #71

Closed
Llammissar opened this issue Apr 27, 2017 · 3 comments
Closed

Field ranges #71

Llammissar opened this issue Apr 27, 2017 · 3 comments

Comments

@Llammissar
Copy link

I think it'd be a boon to usability if we could specify ranges of fields similarly to the shell tool cut. Especially for something like this:

tsv-select -f 1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,$(seq -s, 19 49)

It would be more familiar and more readable to be able to render it like so:

tsv-select -f 1-10,12-17,19-

This becomes especially nice when you have a lot of columns.

And there's the hat trick. ;)

@jondegenhardt
Copy link
Contributor

This is actually next on my todo list, for all the reasons you mention

@Llammissar
Copy link
Author

Oh really? Great! A thought I had: it may be useful to have something like opDollar (e.g. so we can easily express ideas like "all but the last two of however many columns this is"), but I'm not sure how to make it not-super-ugly in the shell.

@jondegenhardt
Copy link
Contributor

jondegenhardt commented May 7, 2017

Added support for field ranges anywhere a list of fields can be entered. A field range is a pair of field numbers separated by a hyphen: 3-7. Reverse order is supported as well: 7-3. A field list is a sequence of field numbers and ranges. e.g: 1,7-14,30-25,9. Some examples:

tsv-select --fields 1,2,17-33,10-7  data.tsv
tsv-summarize --group-by 3-5 --median 7-17
tsv-uniq --fields 7-10 data.tsv

I decided not to support incomplete ranges like 3-. This is a significant complication when lines have variable numbers of fields, and involves changing the inner loop of any tool supporting it. (Even ignoring variable length rows it would have involved significantly more work.) Note that this is not an issue for Unix cut, as it does not support re-ordering fields. It can always print to the end of the line when an incomplete range is involved.

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

3 participants