Subject: bug#13301: patch to preserve field order in cut

From: Brad Cater <[email-masked]>
Date: Fri, 28 Dec 2012 17:19:32 -0500

Hello

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 means that it's necessary to use another process to re-order columns.
I have written a patch for cut.c included in coreutils-8.20 (
http://ftp.gnu.org/gnu/coreutils/coreutils-8.20.tar.xz) that adds a -p
option to preserve field order. This means that doing

echo "a,b,c" | cut -d"," -f2,1

still gives

a,b

but

echo "a,b,c" | cut -d"," -f2,1 -p

gives

b,a

The current implementation of cut.c uses putchar so that a full line need
not be held in memory, whereas holding a full line is required to re-order
the fields rather than printing them from an input stream. This patch uses
putchar when -p is not used, but it buffers a full line when -p is used.

What should I do next? I would like to have someone more experienced than I
evaluate the changes so that I can improve them and add this functionality
to coreutils.

Thank you
-Brad