coreutils
[Top][All Lists]
Advanced

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

Re: [coreutils] cut feature request


From: Laurent Lyaudet
Subject: Re: [coreutils] cut feature request
Date: Tue, 07 Sep 2010 21:43:33 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6

On 07/09/2010 19:52, Eric Blake wrote:
On 09/07/2010 10:29 AM, Laurent Lyaudet wrote:
Hi,
it would be useful that cut handles negative numbers parameters for
columns and fields as "from the end" parameters.
One could select the last field with -f -1 for example. (Currently, -f
-1 do the same that -f 1.)

Thanks for the report. I also wonder if allowing negative end fields for sort -k key specifiers also makes sense.

Thanks for your answer.
I didn't find a previous request that is similar in coreutils archive.
I think using awk or something similar is overkill for solving that
problem.

On the contrary, we tend to take the conservative position that if there is a POSIX-mandated tool that already does what you need, then adding an alternative shortcut to some other tool to do the same thing is very difficult to justify, on the grounds that you cannot rely on our extension, but can rely on awk's behavior, when porting to multiple systems. In other words, the bar for 'convenience' features is rather high before considering additions like this.

I didn't knew for the conservative position. I thought that, of course, it had to be POSIX compliant but there was no restraint on additional features regarding compatibility with other POSIX-compliant systems.
It may help us decide by showing a sample input file and a command line using your proposed extension, along with any awk alternative to do the same, to convince us that the verbosity required in awk is worth such a shortcut (or conversely, that the awk script is already so simple as to not be worth changing cut, as has already been our argument for the numerous times that people suggest teaching cut how to reorder fields).

I'm sorry I don't have a decisive example. All I'm using is a sequence of piped commands on csv and text files like
... | awk -F'/' '{print $FN}' | ...

I would prefer :
... | cut -d'/' -f -1 | ...

If I had to handle flat file and cut the last 5 characters then the example would be more convincing
awk '{print substr($0,length($0)-5)}'
instead of
cut -c -5

I see two other arguments for these feature : cut is compiled command, awk program is interpreted; if reading a script two years after writing it, the "what was I doing here? effect" (or the "how was I doing it? effect" if there is a minimal amount of commentary in the code) will
be decreased.
Let me know what you think about it.

If we do it, I'd like to see it done uniformly across all the coreutils that take partial field specifications. And although I probably won't be the one writing such a patch, it does sound like it still might be justifiable.

Thanks for considering my request.



reply via email to

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