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

Using cuts for 1st and last column from f1 & last columns from f2 doesn't work #4

Open
tinyheero opened this issue Nov 12, 2014 · 2 comments

Comments

@tinyheero
Copy link

Hi,

Perhaps I am misunderstanding how the cuts function works, but according to the documentation if one was to do this:

cuts f1 0 -1 f2

Should lead to 1st & last columns from f1 & last column (last colno seen) from f2.

But given these test data:

f1

a 10
b 12
c 14

f2

i 1
ii 2
iii 3

cuts f1 0 -1 f2

Produces

a 1
b 2
c 3

I thought it would produce

a 10 1
b 12 2
c 14 3

Is this expected? Or a bug?

@arielf
Copy link
Owner

arielf commented Nov 13, 2014

Hi, and thanks for the report.

Interesting corner case I haven't thought about. I'd be inclined to classify this as a bug.

get_args() is not smart enough in the case there are multiple files, and the list is terminated by a file (without a column-spec).

Edit:

Looking deeper, it seems hard to fix because cuts repeats the last arg (column or file) whenever there's no pairing and alows flexible order of parameters. This enables it to work as expected and minimize typing, in many cases like:

# column vs file order is flexible
cuts -1 f1 f2 f3
cuts f1 f2 f3 -1 

and even

cuts f1 -1 f2 f2

All the above will print the last column of the files specified.

So in the corner case above what happens is 0 is paired with the file f1, and -1 is paired with f2.
Looks like I'll have to fix the documentation and help message.

And the work-around would be to repeat f1:

cuts f1 0 f1 -1 f2

@pirance
Copy link

pirance commented Jan 8, 2015

Thanks

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