GNU bug report logs - #13301
patch to preserve field order in cut

Previous Next

Package: coreutils;

Reported by: Brad Cater <bradcater <at> gmail.com>

Date: Fri, 28 Dec 2012 23:27:02 UTC

Severity: normal

Tags: notabug

Merged with 6394, 9507

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 13301 <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: Brad Cater <bradcater <at> gmail.com>
Cc: 13301 <at> debbugs.gnu.org
Subject: Re: bug#13301: patch to preserve field order in cut
Date: Fri, 28 Dec 2012 17:06:48 -0700
severity 13301 wishlist
thanks

Brad Cater wrote:
> I found that
> echo "a,b,c" | cut -d"," -f1,2
> gives the same result as
> echo "a,b,c" | cut -d"," -f2,1

This is because 'cut' has always behaved that way way back forty years
for forever.  So people like me don't consider it a bug.  It is just
the way it was written to work.

The GNU manual documents it this way:

  The list elements can be repeated, can overlap, and can be specified
  in any order; but the selected input is written in the same order
  that it is read, and is written exactly once.

> This means that it's necessary to use another process to re-order columns.

The standard solution is to use 'awk'.  It also has a lot of years
behind it.

  $ echo "a,b,c" | awk -F, '{print$2,$1}'
  b a

Using awk also allows duplication of fields.

  $ echo "a,b,c" | awk -F, '{print$2,$1,$2}'
  b a b

> I have written a patch for cut.c ...

I have not looked at the patch but the barrier to adding new short
options is pretty high.  I will leave that for others to comment.
Personally I don't think it is necessary since awk is already standard
and therefore use of the feature is already available everywhere that
you need it without any changes.

This issue is discussed periodically.  Here are a few that I found
with a quick search.

  http://lists.gnu.org/archive/html/bug-coreutils/2005-06/msg00125.html
  http://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00020.html
  http://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00169.html

Bob




This bug report was last modified 12 years and 128 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.