[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [coreutils] "cut" from last column

From: Philip Ganchev
Subject: Re: [coreutils] "cut" from last column
Date: Sun, 3 Dec 2006 18:17:26 -0500

On 12/3/06, Brian Dessent <address@hidden> wrote:
Philip Ganchev wrote:

> functionality very often when working with tabular data.  Currently,
> the expression to achieve this is clumsy:
> cut -f 3,5-$(echo $(head -1 myfile | wc -w) - 3 | bc) myfile

You're right, that's very clumsy, especially the "head -1" part which is
problematic.  (You should use the unambiguous "head -n 1" instead.)


> The new syntax could use +1 to specify the last column, +2 to specify
> the second-last, etc.  This syntax is the same as for the "tail"
> command.  Then you can achieve the same as the above expression by
> writing:
> cut -f 3,5-+3 myfile

How about:

perl -F'\t' -nae 'print join "\t", @F[2,4..$#F-3]' myfile

Even more verbose and complicated (clumsy).  Plus, it depends on
having Perl, which is not a coreutil as far as I know.  If you are
going to use Perl, why do we need "cut" at all?  It is just sensical
that if a command allows you to cut from the beginning, it will let
you cut from the end.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]