bug-coreutils
[Top][All Lists]
Advanced

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

Re: [coreutils] "cut" from last column


From: Brian Dessent
Subject: Re: [coreutils] "cut" from last column
Date: Sun, 03 Dec 2006 03:01:32 -0800

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

Brian




reply via email to

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