GNU bug report logs -
#9507
cut bug?
Previous Next
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Wed, 14 Sep 2011 10:52:45 -0600
with message-id <4E70DBDD.2070301 <at> redhat.com>
and subject line Re: bug#9507: cut bug?
has caused the debbugs.gnu.org bug report #9507,
regarding cut bug?
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
9507: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9507
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
Hi,
I'm sure this must have been spotted before, but
cut -f2,1
produces the fields in the order 1,2 rather than 2,1. That seems wrong
to me.
Changing it would probably break a thousand scripts. But could we have
an additional option to respect the order of fields given on the command
line? It is a pain to rearrange fields with sed, though of course it can
be done.
Thanks, and keep up the good work.
James
[Message part 4 (text/html, inline)]
[Message part 5 (message/rfc822, inline)]
tag 9507 notabug
merge 6394 9507
thanks
On 09/14/2011 10:20 AM, James Heather wrote:
> Hi,
>
> I'm sure this must have been spotted before, but
>
> cut -f2,1
>
> produces the fields in the order 1,2 rather than 2,1. That seems wrong
> to me.
You're not the first to complain of this, and probably won't be the last.
>
> Changing it would probably break a thousand scripts.
Yep. And it would also violate POSIX, so changing it now is a
non-starter. For reference, here's the POSIX text:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cut.html
"The elements in list can be repeated, can overlap, and can be specified
in any order, but the bytes, characters, or fields selected shall be
written in the order of the input data."
"The list option-arguments are historically used to select the portions
of the line to be written, but do not affect the order of the data. For
example:
echo abcdefghi | cut -c6,2,4-7,1
yields "abdefg"."
> But could we have
> an additional option to respect the order of fields given on the command
> line?
Why? It's already portable to use awk:
awk '{print $2,$1}'
https://lists.gnu.org/archive/html/bug-coreutils/2007-09/msg00169.html
at which point, you have the choice between a POSIX-mandated solution
already on your system, even if you don't use coreutils; or waiting for
a coreutils extension to be written and propagate to your distro, and
which still won't work on other platforms like BSD. You can tell which
way we are leaning.
> It is a pain to rearrange fields with sed, though of course it can
> be done.
awk is better than sed for this task.
--
Eric Blake eblake <at> redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
This bug report was last modified 12 years and 184 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.