arielf / cuts

Unix 'cut' (and 'paste') on steroids: more flexible select columns from files
Artistic License 2.0
66 stars 7 forks source link

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

Open tinyheero opened 9 years ago

tinyheero commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

Thanks