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

tsv-select: Inverse selection #72

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

tsv-select: Inverse selection #72

Llammissar opened this issue Apr 27, 2017 · 3 comments

Comments

@Llammissar
Copy link

I'm on fire! :D Just thought of this while I was writing #71: a way to drop columns instead of select them would probably be even clearer in many cases. Consider:
tsv-select -f 1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,$(seq -s, 19 49) rawdata.tsv
vs.
tsv-select --inverse -f 9,18 rawdata.tsv
...or better:
tsv-select --inverse 9,18 rawdata.tsv
...because you may want to rearrange what's left:
tsv-select -v 9,18 -f 1,43,38 -r last (short option -v, like grep)
In the above example 9 and 18 are still not part of the output despite the -r last, and numbering doesn't shift for other addressing (i.e. 43 wasn't 45 before columns were removed).

Of course, it'd pair well with ranges, too, so they're not mutually exclusive:
tsv-select -v 2-9

Trying to include and exclude a field at the same time... should probably just be an error, though that could be annoying at times.

I'm not sold on the name/shortening, either. It'd make more sense for my initial thought (tsv-select -inverse -f 9,18), than the form I'd consider more usable.

@jondegenhardt
Copy link
Contributor

Thanks! I'll look into this as part of field ranges.

@jondegenhardt
Copy link
Contributor

Leaving this open as a separate enhancement from field ranges (Issue #71, PR #77). It's meaningfully different. For tsv-select, when variable line lengths are involved, it actually introduces new functionality, not just a more convenient way to specify fields.

@jondegenhardt
Copy link
Contributor

Feature added in release 1.6.0, PR #267. This was done by adding a --e|exclude option to tsv-select. Some examples:

$   # Drop the first field, keep everything else.
$   # Equivalent to `cut -f 2- file.tsv`
$   tsv-select --exclude 1 file.tsv

$   # Drop fields 3-10, keep everything else
$   tsv-select --exclude 3-10 file.tsv

$   # Move field 2 to the start of the line, drop fields 10-15
$   tsv-select -f 2 -e 10-15 file.tsv

$   # Move field 2 to the end, dropping fields 10-15
$   tsv-select -f 2 --rest first -e 10-15 file.tsv

For more info see PR #267 and the tsv-select reference doc.

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

2 participants