+1

On Fri, Sep 10, 2010 at 11:25 AM, Henrikki Almusa <[email protected]>wrote:

> Laurent Lyaudet wrote:
>>
>>> it would be useful that cut handles negative numbers parameters for
>>> columns and fields as "from the end" parameters.
>>> ...
>>>
>>> I think using awk or something similar is overkill for solving that
>>> problem.
>>>
>>
>> Why?  I think awk is the perfect tool for it.  It already handles the
>> problem well.  It is standard.
>>
>> Awk:
>>  $ echo one two three | awk '{print$NF}'
>>  three
>>
>>  $ echo one two three | awk '{print$(NF-1)}'
>>  two
>>
>> Perl:
>>  $ echo one two three | perl -lane 'print $F[-1]'
>>  three
>>
>> If cut included all of the features of awk (or perl) then cut would
>> also be overkill for the problem too, right?  Except then there
>> wouldn't be a way to avoid the bloat by using the small and light
>> weight cut, because cut wouldn't be small and light weight anymore,
>> right?
>>
>
>
yes awk it is standard, but since it's a multi-purpose tool, it's sometimes
more difficult to read (as a human) in big script files than commands like
cut.




> I'd like to add my voice to adding this feature as well. I have a table
> from which I want to retrieve 3rd and 2nd last columns. I can do this with
> perl
>
> cat foo.csv | perl -lane 'print join("\t",@F[$#F-2 .. $#F-1])' > bar.csv
>
> I think it would be much nicer to be able to use cut in here.
>
> cat foo.csv | cut -f-2,-3 > bar.csv
>
>
Sometimes, this kind of problem can be solved by using rev:

$ cat foo.csv | rev | cut -f2,3 | rev



> Nobody is saying that all the functions of perl (or awk) should be in cut,
> but ability to start from end of line instead of start would be useful.
> Alternative to -N (as that can be mixed to other options or valid syntax)
> might be
>
> cat foo.csv | cut --start-end -f2,3 > bar.csv
>
>
I like the idea of negative fields number, but I have no idea if it would
kill performances or not...



> Thanks,
> Ps. please CC me as I'm not on coreutils list.
> --
> Henrikki Almusa
>

Reply via email to