bug-coreutils
[Top][All Lists]
Advanced

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

Re: cut(1) feature request


From: Jim Meyering
Subject: Re: cut(1) feature request
Date: Sat, 18 Jun 2005 22:11:27 +0200

Philip Rowlands <address@hidden> wrote:
>>I'm missing a feature in cut(1) and wanted to know if i) one can change
>>the behaviour of the return fields or ii) add an additional parameter
>>(let's say -F) to GNU cut. The latter option would ensure that things
>>don't get broken, whereas the first option seems more intuitiv.
>
> The spec mandates that the selected fields be returned in order:
> http://www.opengroup.org/onlinepubs/009695399/utilities/cut.html
>
> Note in the "rationale" section the proposal to add "-o" as as argument
> to indicate that list order should be preserved.
>
> Whether or not GNU cut should use the exact argument "-o", I think it
> would be a useful feature. I can't speak for the coreutils maintainer,
> but patches are usually welcome, especially if supplied with good
> documentation and testing.

Many have been tempted to make such an addition.
I've tried to resist it, because this is something
that can already be done easily with other widely available tools.

You can use awk like this:

  $ printf 'a b c d e f\n'|awk '{print $2,$1,$5}'
  b a e

Or if you want to use e.g., `:' as the input field separator,

  $ printf 'a:b:c:d:e:f\n'|awk -F: '{print $2,$1,$5}'
  b a e

Then you don't have to worry about using some non-portable
GNU extension to cut in your scripts.

In spite of all of that, the existing behavior (of not honoring
the user-specified field/column-number ordering) is non-intuitive
enough that I'd consider a patch adding an option to make cut
provide the more sensible behavior.




reply via email to

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