From unknown Wed Jun 18 00:17:16 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#13301 <13301@debbugs.gnu.org> To: bug#13301 <13301@debbugs.gnu.org> Subject: Status: patch to preserve field order in cut Reply-To: bug#13301 <13301@debbugs.gnu.org> Date: Wed, 18 Jun 2025 07:17:16 +0000 retitle 13301 patch to preserve field order in cut reassign 13301 coreutils submitter 13301 Brad Cater severity 13301 normal tag 13301 notabug thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 28 18:26:34 2012 Received: (at submit) by debbugs.gnu.org; 28 Dec 2012 23:26:34 +0000 Received: from localhost ([127.0.0.1]:35323 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TojJx-0007yx-V8 for submit@debbugs.gnu.org; Fri, 28 Dec 2012 18:26:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39834) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1ToiID-0006Ma-Ap for submit@debbugs.gnu.org; Fri, 28 Dec 2012 17:20:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ToiHG-0006XC-Sg for submit@debbugs.gnu.org; Fri, 28 Dec 2012 17:19:46 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:33393) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ToiHG-0006X7-P6 for submit@debbugs.gnu.org; Fri, 28 Dec 2012 17:19:42 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ToiHB-00070k-OJ for bug-coreutils@gnu.org; Fri, 28 Dec 2012 17:19:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ToiH8-0006WO-To for bug-coreutils@gnu.org; Fri, 28 Dec 2012 17:19:37 -0500 Received: from mail-ee0-f51.google.com ([74.125.83.51]:52220) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ToiH8-0006WE-HC for bug-coreutils@gnu.org; Fri, 28 Dec 2012 17:19:34 -0500 Received: by mail-ee0-f51.google.com with SMTP id d4so5292564eek.10 for ; Fri, 28 Dec 2012 14:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=kopsOJh1Q/ASBE6m0xNDy7vF7CvQ7HB5xsP5u+f6U8g=; b=kZTBRUCjYYgdNbp7ncBWNOnE8TGAAKoOpzxD8GU2AUYtz4Rd1DjmCPqhqeVDPPPNhS HS+AiHZbpU3AysubEjEadyZSX9jXq2SWnkMeNq201HtQZ3hizNaXEv5mL8Z0+Q2yGSfN FrfCtdmy7oUjhEOSR3cG3lOHxGmB1IWUEbKgljsIjxJWwxDHgP63UXxYg0oDiy6R8Iz6 DWTHgKaDOZLdRqmuWad8PFRKqu7DdFZvbdplwoiadu2yYm8ID8Ol+Na9HfC6kvG2XQaT Y3ZOlQ4KNhvKpl6EzaY0OKjTZx9z1qMoY/05ysA6q4JCMchaJanAsNcB1fojd7cnvD6K XILg== MIME-Version: 1.0 Received: by 10.14.202.3 with SMTP id c3mr89704108eeo.4.1356733173259; Fri, 28 Dec 2012 14:19:33 -0800 (PST) Received: by 10.14.98.79 with HTTP; Fri, 28 Dec 2012 14:19:32 -0800 (PST) Date: Fri, 28 Dec 2012 17:19:32 -0500 Message-ID: Subject: patch to preserve field order in cut From: Brad Cater To: bug-coreutils@gnu.org Content-Type: multipart/mixed; boundary=047d7b3436acd8dea504d1f10ec8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -3.4 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 28 Dec 2012 18:26:32 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.4 (---) --047d7b3436acd8dea504d1f10ec8 Content-Type: multipart/alternative; boundary=047d7b3436acd8dea004d1f10ec6 --047d7b3436acd8dea004d1f10ec6 Content-Type: text/plain; charset=ISO-8859-1 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 --047d7b3436acd8dea004d1f10ec6 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
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 incl= uded 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<= /div>

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 printin= g them from an input stream. This patch uses putchar when -p is not used, b= ut 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
--047d7b3436acd8dea004d1f10ec6-- --047d7b3436acd8dea504d1f10ec8 Content-Type: application/octet-stream; name="cut.8.20.preserve_field_order.patch" Content-Disposition: attachment; filename="cut.8.20.preserve_field_order.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hb9vt42c0 LS0tIGN1dC5jCTIwMTItMTItMjggMTU6MTk6NTcuMzQ1OTg1MjI1IC0wNTAwCisrKyBzcmMvY3V0 LmMJMjAxMi0xMi0yOCAxNjo1NTo1MS45MDYwNjI4MjEgLTA1MDAKQEAgLTQ1LDYgKzQ1LDIyIEBA CiAgIHByb3Blcl9uYW1lICgiRGF2aWQgTWFjS2VuemllIiksIFwKICAgcHJvcGVyX25hbWUgKCJK aW0gTWV5ZXJpbmciKQogCisvKiBXaGVuIGluaXRpYWxpemluZyBhbiBhcnJheSB0byBob2xkIGVh Y2ggbGluZSB3aGVuIHVzaW5nIC0tcHJlc2VydmUtb3JkZXIsCisgICB0aGVyZSBtdXN0IGJlIGEg c2VudGluZWwgdmFsdWUgdGhhdCBzaWduaWZpZXMgdGhhdCB0aGUgbmV4dCBjaGFyYWN0ZXIgYWRk ZWQKKyAgIHRvIHRoZSBhcnJheSB3aWxsIGJlIHRoZSBmaXJzdCBjaGFyYWN0ZXIgaW4gdGhhdCBm aWVsZC4gICovCisjZGVmaW5lIENFTExfU0VOVElORUwgJ1wwJworCisvKiBUaGlzIHNob3VsZCBi ZSBhbmFsb2dvdXMgdG8gdGhlIHByb2JsZW0gb2Ygc2VhcmNoaW5nIGZvciBhbiBvYmplY3QgYnkK KyA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X2VuZHBvaW50ICsgMSkgKiBzaXplb2YgKHNp emVfdCkpOworICBtZW1zZXQgKGZpZWxkX29yZGVyLCAwLCAobWF4X3JhbmdlX2VuZHBvaW50ICsg MSkgKiBzaXplb2YgKHNpemVfdCkpOworCisgIC8qIHBvcyB3aWxsIGhlbHAga2V5IGludG8gZmll bGRfb3JkZXIgd2hlbiB1c2luZyAtLXByZXNlcnZlLW9yZGVyLiAgKi8KKyAgc2l6ZV90IHBvcyA9 IDA7CisKKyAgLyogU2V0IHRoZSBmaWVsZF9vcmRlciB3aGVuIHVzaW5nIC0tcHJlc2VydmUtb3Jk ZXIuICBUaGlzIG11c3QgaGFwcGVuIGJlZm9yZQorICAgICBjYWxsaW5nIHFzb3J0IG9uIHRoZSBy YW5nZXMuICAqLworICBpZiAocHJlc2VydmVfZmllbGRfb3JkZXIpIHsKKyAgICBmb3IgKGkgPSAw OyBpIDwgbl9ycDsgaSsrKSB7CisgICAgICBzaXplX3QgaiA9IHJwW2ldLmxvOworCisgICAgICBp ZiAoaiA8PSBycFtpXS5oaSAmJiAhaXNfcHJpbnRhYmxlX2ZpZWxkKGopKSB7CisgICAgICAgIC8q IEtleSBpbnRvIGZpZWxkX29yZGVyLiBUaGlzIGlzIHRoZSBzdGFydCBvZiB0aGUgcmFuZ2UuICAq LworICAgICAgICArK3BvczsKKyAgICAgICAgZmllbGRfb3JkZXJbcG9zXSA9IGo7CisgICAgICB9 CisgICAgICBmb3IgKCsrajsgaiA8PSBycFtpXS5oaTsgaisrKSB7CisgICAgICAgIC8qIFNpbmNl IHRoaXMgaXMgYSByYW5nZSwgd2UgbG9vayBhdCB0aGUgcHJldmlvdXMgY2VsbCBhbmQgaW5jcmVt ZW50LiAgKi8KKyAgICAgICAgKytwb3M7CisgICAgICAgIGZpZWxkX29yZGVyW3Bvc10gPSBmaWVs ZF9vcmRlcltqLTFdICsgMTsKKyAgICAgIH0KKyAgICB9CisgIH0KKwogICBxc29ydCAocnAsIG5f cnAsIHNpemVvZiAocnBbMF0pLCBjb21wYXJlX3Jhbmdlcyk7CiAKICAgLyogU2V0IHRoZSBhcnJh eSBlbnRyaWVzIGNvcnJlc3BvbmRpbmcgdG8gaW50ZWdlcnMgaW4gdGhlIHJhbmdlcyBvZiBSUC4g ICovCkBAIC01MTYsMTEgKzU2NywxMiBAQAogICAgICAgICAgaW5kZXggdGhhdCBpcyBub3QgcGFy dCBvZiBhbnkgb3RoZXIgKGxvLi5oaV0gcmFuZ2UuICAqLwogICAgICAgcnNpX2NhbmRpZGF0ZSA9 IGNvbXBsZW1lbnQgPyBycFtpXS5oaSArIDEgOiBycFtpXS5sbzsKICAgICAgIGlmIChvdXRwdXRf ZGVsaW1pdGVyX3NwZWNpZmllZAotICAgICAgICAgICYmICFpc19wcmludGFibGVfZmllbGQgKHJz aV9jYW5kaWRhdGUpKQorICAgICAgICAgICYmICFpc19wcmludGFibGVfZmllbGQgKHJzaV9jYW5k aWRhdGUpKSB7CiAgICAgICAgIG1hcmtfcmFuZ2Vfc3RhcnQgKHJzaV9jYW5kaWRhdGUpOwotCi0g ICAgICBmb3IgKGogPSBycFtpXS5sbzsgaiA8PSBycFtpXS5oaTsgaisrKQorICAgICAgfQorICAg ICAgZm9yIChqID0gcnBbaV0ubG87IGogPD0gcnBbaV0uaGk7IGorKykgewogICAgICAgICBtYXJr X3ByaW50YWJsZV9maWVsZCAoaik7CisgICAgICB9CiAgICAgfQogCiAgIGlmIChvdXRwdXRfZGVs aW1pdGVyX3NwZWNpZmllZApAQCAtNTMzLDYgKzU4NSwzMCBAQAogICByZXR1cm4gZmllbGRfZm91 bmQ7CiB9CiAKKy8qIEluaXRpYWxpemUgYW4gYXJyYXkgdGhhdCB3aWxsIGhvbGQgdGhlIHByaW50 YWJsZSBmaWVsZHMgd2hlbiB1c2luZworICAgLS1wcmVzZXJ2ZS1vcmRlciB3aXRoIENFTExfU0VO VElORUwuICAqLworc3RhdGljIHZvaWQKK2luaXRpYWxpemVfYXJyYXkoY2hhciAqKiogYXJyYXks IHNpemVfdCBwcmV2X2FycmF5c2l6ZSwgc2l6ZV90IG5ld19hcnJheXNpemUpCit7CisgIHNpemVf dCBwcmludF9pOworICBmb3IgKHByaW50X2kgPSBwcmV2X2FycmF5c2l6ZTsgcHJpbnRfaSA8IG5l d19hcnJheXNpemU7IHByaW50X2krKykgeworICAgIGNoYXIgKiogYSA9IDA7CisgICAgYSA9IHht YWxsb2MoIElOSVRJQUxfQVJSQVlfU0laRSAqIHNpemVvZihjaGFyICoqKSApOworICAgIGFbMF0g PSAoY2hhciAqKSBDRUxMX1NFTlRJTkVMOworICAgIGFycmF5W3ByaW50X2ldID0gYTsKKyAgfQor fQorCisvKiBJbml0aWFsaXplIGFuIGFycmF5IHRoYXQgd2lsbCBob2xkIHRoZSBwcmludGFibGUg ZmllbGRzIHdoZW4gdXNpbmcKKyAgIC0tcHJlc2VydmUtb3JkZXIuICAqLworc3RhdGljIGNoYXIg KioqCithbGxvY19hcnJheShjaGFyICoqKiBhcnJheSwgc2l6ZV90IHNpemUpCit7CisgIGFycmF5 ID0geG1hbGxvYyggc2l6ZSAqIHNpemVvZihjaGFyICoqKSApOworICBpbml0aWFsaXplX2FycmF5 KGFycmF5LCAwLCBzaXplKTsKKyAgcmV0dXJuIGFycmF5OworfQorCiAvKiBSZWFkIGZyb20gc3Ry ZWFtIFNUUkVBTSwgcHJpbnRpbmcgdG8gc3RhbmRhcmQgb3V0cHV0IGFueSBzZWxlY3RlZCBieXRl cy4gICovCiAKIHN0YXRpYyB2b2lkCkBAIC02MDUsNiArNjgxLDE0IEBACiAgICAgIFRoYXQgaXMg YmVjYXVzZSBhIG5vbi1kZWxpbWl0ZWQgbGluZSBoYXMgZXhhY3RseSBvbmUgZmllbGQuICAqLwog ICBidWZmZXJfZmlyc3RfZmllbGQgPSAoc3VwcHJlc3Nfbm9uX2RlbGltaXRlZCBeICFwcmludF9r dGggKDEsIE5VTEwpKTsKIAorICAvKiBLZWVwIHRyYWNrIG9mIHRoZSBzaXplIG9mIHRoZSBhcnJh eSB0aGF0IHdlIG5lZWQgYW5kIGluaXRpYWxpemUgdGhlIGFycmF5CisgICAgIGZvciAtLXByZXNl cnZlLW9yZGVyLiAgKi8KKyAgc2l6ZV90IGFycmF5c2l6ZSA9IElOSVRJQUxfQVJSQVlfU0laRTsK KyAgY2hhciAqKiogYXJyYXkgPSAwOworICBpZiAocHJlc2VydmVfZmllbGRfb3JkZXIpIHsKKyAg ICBhcnJheSA9IGFsbG9jX2FycmF5KGFycmF5LCBhcnJheXNpemUpOworICB9CisKICAgd2hpbGUg KDEpCiAgICAgewogICAgICAgaWYgKGZpZWxkX2lkeCA9PSAxICYmIGJ1ZmZlcl9maXJzdF9maWVs ZCkKQEAgLTY1OSwxNCArNzQzLDQ2IEBACiAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgIGlm IChmb3VuZF9hbnlfc2VsZWN0ZWRfZmllbGQpCiAgICAgICAgICAgICAgICAgeworICAgICAgICAg ICAgICAgICAgLyogV3JpdGUgb3V0IHRoZSBkZWxpbWl0ZXIgZm9yIC0tcHJlc2VydmUtb3JkZXIu ICAqLworICAgICAgICAgICAgICAgICAgaWYgKCFwcmVzZXJ2ZV9maWVsZF9vcmRlcikgewogICAg ICAgICAgICAgICAgICAgZndyaXRlIChvdXRwdXRfZGVsaW1pdGVyX3N0cmluZywgc2l6ZW9mIChj aGFyKSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0X2RlbGltaXRlcl9sZW5ndGgs IHN0ZG91dCk7CisgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgfQogICAgICAg ICAgICAgICBmb3VuZF9hbnlfc2VsZWN0ZWRfZmllbGQgPSB0cnVlOwogCiAgICAgICAgICAgICAg IHdoaWxlICgoYyA9IGdldGMgKHN0cmVhbSkpICE9IGRlbGltICYmIGMgIT0gJ1xuJyAmJiBjICE9 IEVPRikKICAgICAgICAgICAgICAgICB7Ci0gICAgICAgICAgICAgICAgICBwdXRjaGFyIChjKTsK KyAgICAgICAgICAgICAgICAgIGlmIChwcmVzZXJ2ZV9maWVsZF9vcmRlcikgeworICAgICAgICAg ICAgICAgICAgICAvKiBTdG9yZSB0aGUgcHJpbnRhYmxlIGZpZWxkcyB3aGVuIHVzaW5nIC0tcHJl c2VydmUtb3JkZXIuICAqLworICAgICAgICAgICAgICAgICAgICBzaXplX3Qgb3V0cHV0X2ZpZWxk X2lkeCA9IDA7CisgICAgICAgICAgICAgICAgICAgIHdoaWxlICgxKSB7CisgICAgICAgICAgICAg ICAgICAgICAgaWYgKGZpZWxkX29yZGVyW291dHB1dF9maWVsZF9pZHhdID09IGZpZWxkX2lkeCkg eworICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICAgICAgICAgICAg fQorICAgICAgICAgICAgICAgICAgICAgICsrb3V0cHV0X2ZpZWxkX2lkeDsKKyAgICAgICAgICAg ICAgICAgICAgfQorICAgICAgICAgICAgICAgICAgICBpZiAoKG91dHB1dF9maWVsZF9pZHggKyAx KSA+PSBhcnJheXNpemUpIHsKKyAgICAgICAgICAgICAgICAgICAgICBzaXplX3QgcHJldl9hcnJh eXNpemUgPSBhcnJheXNpemU7CisgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGFycmF5c2l6 ZSA8IG91dHB1dF9maWVsZF9pZHggKyAxKSB7CisgICAgICAgICAgICAgICAgICAgICAgICBhcnJh eXNpemUgKj0gQVJSQVlfU0laRV9NVUxUSVBMSUVSOworICAgICAgICAgICAgICAgICAgICAgIH0K KyAgICAgICAgICAgICAgICAgICAgICBhcnJheSA9IHJlYWxsb2MoYXJyYXksIGFycmF5c2l6ZSAq IHNpemVvZihjaGFyICoqKSk7CisgICAgICAgICAgICAgICAgICAgICAgaW5pdGlhbGl6ZV9hcnJh eShhcnJheSwgcHJldl9hcnJheXNpemUsIGFycmF5c2l6ZSk7CisgICAgICAgICAgICAgICAgICAg IH0KKyAgICAgICAgICAgICAgICAgICAgaWYgKGFycmF5W291dHB1dF9maWVsZF9pZHhdWzBdID09 IENFTExfU0VOVElORUwpIHsKKyAgICAgICAgICAgICAgICAgICAgICBhcnJheVtvdXRwdXRfZmll bGRfaWR4XVswXSA9IChjaGFyICopIGM7CisgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7Cisg ICAgICAgICAgICAgICAgICAgICAgY2hhciB0bXBbMl07CisgICAgICAgICAgICAgICAgICAgICAg dG1wWzBdID0gYzsKKyAgICAgICAgICAgICAgICAgICAgICB0bXBbMV0gPSAnXDAnOworICAgICAg ICAgICAgICAgICAgICAgIC8vc3RyY2F0KCZhcnJheVtvdXRwdXRfZmllbGRfaWR4XVswXSwgJnRt cCk7CisgICAgICAgICAgICAgICAgICAgICAgc3RyY2F0KGFycmF5W291dHB1dF9maWVsZF9pZHhd LCAmdG1wKTsKKyAgICAgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgICAgICAgfSBlbHNl IHsKKyAgICAgICAgICAgICAgICAgIC8qIFByaW50IHRoZSBjdXJyZW50IGNoYXIgd2hlbiBub3Qg dXNpbmcgLS1wcmVzZXJ2ZS1vcmRlci4gICovCisgICAgICAgICAgICAgICAgICAgIHB1dGNoYXIg KGMpOworICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAg IH0KICAgICAgICAgICBlbHNlCkBAIC02ODAsNiArNzk2LDI0IEBACiAKICAgICAgIGlmIChjID09 ICdcbicpCiAgICAgICAgIHsKKyAgICAgICAgICAvKiBQcmludCB0aGUgcHJpbnRhYmxlIGZpZWxk cyB3aGVuIHVzaW5nIC0tcHJlc2VydmUtb3JkZXIuICAqLworICAgICAgICAgIGlmIChwcmVzZXJ2 ZV9maWVsZF9vcmRlcikgeworICAgICAgICAgICAgYm9vbCBkaWRfZmlyc3QgPSBmYWxzZTsKKyAg ICAgICAgICAgIHNpemVfdCBwcmludF9qID0gMDsKKyAgICAgICAgICAgIHdoaWxlIChwcmludF9q IDwgYXJyYXlzaXplKSB7CisgICAgICAgICAgICAgIGlmIChwcmludF9rdGgoZmllbGRfb3JkZXJb cHJpbnRfal0sIE5VTEwpKSB7CisgICAgICAgICAgICAgICAgaWYgKGRpZF9maXJzdCkgeworICAg ICAgICAgICAgICAgICAgZndyaXRlIChvdXRwdXRfZGVsaW1pdGVyX3N0cmluZywgc2l6ZW9mIChj aGFyKSwKKyAgICAgICAgICAgICAgICAgICAgb3V0cHV0X2RlbGltaXRlcl9sZW5ndGgsIHN0ZG91 dCk7CisgICAgICAgICAgICAgICAgfQorICAgICAgICAgICAgICAgIHByaW50ZiAoXygiJXMiKSwg YXJyYXlbcHJpbnRfal0pOworICAgICAgICAgICAgICAgIGRpZF9maXJzdCA9IHRydWU7CisgICAg ICAgICAgICAgIH0KKyAgICAgICAgICAgICAgKytwcmludF9qOworICAgICAgICAgICAgfQorICAg ICAgICAgICAgZnJlZSAoYXJyYXkpOworICAgICAgICAgICAgYXJyYXkgPSBhbGxvY19hcnJheShh cnJheSwgYXJyYXlzaXplKTsKKyAgICAgICAgICB9CiAgICAgICAgICAgYyA9IGdldGMgKHN0cmVh bSk7CiAgICAgICAgICAgaWYgKGMgIT0gRU9GKQogICAgICAgICAgICAgewpAQCAtNzc4LDcgKzkx Miw3IEBACiAgIGRlbGltID0gJ1wwJzsKICAgaGF2ZV9yZWFkX3N0ZGluID0gZmFsc2U7CiAKLSAg d2hpbGUgKChvcHRjID0gZ2V0b3B0X2xvbmcgKGFyZ2MsIGFyZ3YsICJiOmM6ZDpmOm5zIiwgbG9u Z29wdHMsIE5VTEwpKSAhPSAtMSkKKyAgd2hpbGUgKChvcHRjID0gZ2V0b3B0X2xvbmcgKGFyZ2Ms IGFyZ3YsICJiOmM6ZDpmOm5wcyIsIGxvbmdvcHRzLCBOVUxMKSkgIT0gLTEpCiAgICAgewogICAg ICAgc3dpdGNoIChvcHRjKQogICAgICAgICB7CkBAIC03OTksNiArOTMzLDExIEBACiAgICAgICAg ICAgc3BlY19saXN0X3N0cmluZyA9IG9wdGFyZzsKICAgICAgICAgICBicmVhazsKIAorICAgICAg ICBjYXNlICdwJzoKKyAgICAgICAgICAvKiBQcmVzZXJ2ZSBmaWVsZCBvcmRlci4gKi8KKyAgICAg ICAgICBwcmVzZXJ2ZV9maWVsZF9vcmRlciA9IHRydWU7CisgICAgICAgICAgYnJlYWs7CisKICAg ICAgICAgY2FzZSAnZCc6CiAgICAgICAgICAgLyogTmV3IGRlbGltaXRlci4gKi8KICAgICAgICAg ICAvKiBJbnRlcnByZXQgLWQgJycgdG8gbWVhbiAndXNlIHRoZSBOVUwgYnl0ZSBhcyB0aGUgZGVs aW1pdGVyLicgICovCkBAIC04NjYsNiArMTAwNSwxMCBAQAogICAgICAgICBGQVRBTF9FUlJPUiAo XygibWlzc2luZyBsaXN0IG9mIHBvc2l0aW9ucyIpKTsKICAgICB9CiAKKyAgaWYgKGNvbXBsZW1l bnQgJiYgcHJlc2VydmVfZmllbGRfb3JkZXIpIHsKKyAgICBGQVRBTF9FUlJPUiAoXygiLS1jb21w bGVtZW50IGlzIGluY29tcGF0aWJsZSB3aXRoIC0tcHJlc2VydmUtb3JkZXIiKSk7CisgIH0KKwog ICBpZiAoIWRlbGltX3NwZWNpZmllZCkKICAgICBkZWxpbSA9ICdcdCc7CiAK --047d7b3436acd8dea504d1f10ec8-- From debbugs-submit-bounces@debbugs.gnu.org Fri Dec 28 19:07:48 2012 Received: (at 13301) by debbugs.gnu.org; 29 Dec 2012 00:07:48 +0000 Received: from localhost ([127.0.0.1]:35365 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tojxs-0001Uw-0n for submit@debbugs.gnu.org; Fri, 28 Dec 2012 19:07:48 -0500 Received: from joseki.proulx.com ([216.17.153.58]:59737) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Tojxp-0001Un-H6 for 13301@debbugs.gnu.org; Fri, 28 Dec 2012 19:07:46 -0500 Received: from dismay.proulx.com (dismay.proulx.com [172.27.61.4]) by joseki.proulx.com (Postfix) with ESMTP id 73941211D6; Fri, 28 Dec 2012 17:06:49 -0700 (MST) Received: by dismay.proulx.com (Postfix, from userid 1000) id 8CEA0D207DE; Fri, 28 Dec 2012 17:06:48 -0700 (MST) Date: Fri, 28 Dec 2012 17:06:48 -0700 From: Bob Proulx To: Brad Cater Subject: Re: bug#13301: patch to preserve field order in cut Message-ID: <20121229000648.GB4838@dismay.proulx.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Spam-Score: 0.8 (/) X-Debbugs-Envelope-To: 13301 Cc: 13301@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -0.0 (/) 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 From debbugs-submit-bounces@debbugs.gnu.org Sat Dec 29 11:21:10 2012 Received: (at 13301) by debbugs.gnu.org; 29 Dec 2012 16:21:10 +0000 Received: from localhost ([127.0.0.1]:36299 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Toz9o-0001WB-UL for submit@debbugs.gnu.org; Sat, 29 Dec 2012 11:21:10 -0500 Received: from mail-ee0-f49.google.com ([74.125.83.49]:36837) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1Toz9k-0001Vx-Oq for 13301@debbugs.gnu.org; Sat, 29 Dec 2012 11:21:06 -0500 Received: by mail-ee0-f49.google.com with SMTP id c4so5532565eek.22 for <13301@debbugs.gnu.org>; Sat, 29 Dec 2012 08:20:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2u26KDt1IRq56+wmsKOXMtRnzdaGzOuXZ+y1UB3r4mE=; b=RD7dPO0vBOchg+6DO8inURvSRCfW96V9PpvZONdK6UPqK8igU/LDJ77LC+xXIiB3Q9 7Ztb9Z+yDy/Q52tuKEFw3jViJvFodLDnpTPRkCx4K63k7jtYZYBfsSiQDYY+HQFvl7Wf mqYPGc5JgYlJ8ScKvs5PwT/DFIkz5gIrZ9Gwm6jJyyxPiZAx94hmd5+BwbiwFbOnnCTl JWFbie9ALb6ZC0BwQoRdc8NrWVZMQH35UmJHLtbvkBQwBOSFYk+rLVA0QVia74it7XLY xzAs1FzKpQSVT0ZsF6Po7+qCO6b5VHKrHXUrIHJqbJMMLLmJeH92YJmEpBJKvrMIWv0+ cvlw== MIME-Version: 1.0 Received: by 10.14.215.194 with SMTP id e42mr96269924eep.32.1356798004786; Sat, 29 Dec 2012 08:20:04 -0800 (PST) Received: by 10.14.98.79 with HTTP; Sat, 29 Dec 2012 08:20:04 -0800 (PST) In-Reply-To: <20121229000648.GB4838@dismay.proulx.com> References: <20121229000648.GB4838@dismay.proulx.com> Date: Sat, 29 Dec 2012 11:20:04 -0500 Message-ID: Subject: Re: bug#13301: patch to preserve field order in cut From: Brad Cater To: Bob Proulx Content-Type: multipart/alternative; boundary=e89a8f923f501b776304d20027fd X-Spam-Score: 0.1 (/) X-Debbugs-Envelope-To: 13301 Cc: 13301@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: 0.1 (/) --e89a8f923f501b776304d20027fd Content-Type: text/plain; charset=ISO-8859-1 Hi Bob Thanks for the quick response. I'm with you: let's not break something that has been working for a long time. That's why I think that the new functionality should be a new option rather than a replacement of existing behavior. I read those example requests that you sent as well as a few on Stackoverflow like this one: http://stackoverflow.com/questions/1037171/forcing-the-order-of-output-fields-from-cut-command It seems like people want this, but I couldn't find anyone who had written it, so I thought that the barrier was the effort to make it work. Admittedly, the patch that I submitted would require additional effort since this is my first foray into Coreutils hacking. Even if it's not adopted into the mainline, I'd be glad to read evaluations of the code so that I could improve it for myself. Thanks in general for GNU. It rocks. -Brad On Fri, Dec 28, 2012 at 7:06 PM, Bob Proulx wrote: > 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 > --e89a8f923f501b776304d20027fd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Bob

Thanks for the quick response.

I'm with you: let's not break somethi= ng that has been working for a long time. That's why I think that the n= ew functionality should be a new option rather than a replacement of existi= ng behavior.

I read those example requests that you sent= as well as a few on Stackoverflow like this one:


It seems like people want this, but I= couldn't find anyone who had written it, so I thought that the barrier= was the effort to make it work. Admittedly, the patch that I submitted wou= ld require additional effort since this is my first foray into Coreutils ha= cking. Even if it's not adopted into the mainline, I'd be glad to r= ead evaluations of the code so that I could improve it for myself.

Thanks in general for GNU. It rocks.
<= div style>
-Brad
=

On Fri, Dec 28, 2012 at 7:06 PM, Bob Pro= ulx <bob@proulx.com> wrote:
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 ye= ars
for forever. =A0So people like me don't consider it a bug. =A0It is jus= t
the way it was written to work.

The GNU manual documents it this way:

=A0 The list elements can be repeated, can overlap, and can be specified =A0 in any order; but the selected input is written in the same order
=A0 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'. =A0It also has a lot of year= s
behind it.

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

Using awk also allows duplication of fields.

=A0 $ echo "a,b,c" | awk -F, '{print$2,$1,$2}'
=A0 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. =A0I will leave that for others to comment.
Personally I don't think it is necessary since awk is already standard<= br> and therefore use of the feature is already available everywhere that
you need it without any changes.

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

=A0 http://lists.gnu.org/archive/html/bug-coreutil= s/2005-06/msg00125.html
=A0 http://lists.gnu.org/archive/html/bug-coreutil= s/2007-09/msg00020.html
=A0 http://lists.gnu.org/archive/html/bug-coreutil= s/2007-09/msg00169.html

Bob

--e89a8f923f501b776304d20027fd-- From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 13 21:09:38 2013 Received: (at 13301) by debbugs.gnu.org; 14 Jan 2013 02:09:38 +0000 Received: from localhost ([127.0.0.1]:58923 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TuZUY-0004cN-0w for submit@debbugs.gnu.org; Sun, 13 Jan 2013 21:09:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:23714) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TuZUV-0004cB-27; Sun, 13 Jan 2013 21:09:36 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0E29CqL010440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 13 Jan 2013 21:09:12 -0500 Received: from [10.36.116.27] (ovpn-116-27.ams2.redhat.com [10.36.116.27]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0E298NZ026283 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 13 Jan 2013 21:09:10 -0500 Message-ID: <50F368C4.2090906@draigBrady.com> Date: Mon, 14 Jan 2013 02:09:08 +0000 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 MIME-Version: 1.0 To: Brad Cater Subject: Re: bug#13301: patch to preserve field order in cut References: <20121229000648.GB4838@dismay.proulx.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id r0E29CqL010440 X-Spam-Score: -4.2 (----) X-Debbugs-Envelope-To: 13301 Cc: 13301@debbugs.gnu.org, Bob Proulx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.0 (-----) unarchive 6394 forcemerge 6394 13301 stop Note I documented how to achieve this with `awk` or `join` in the coreutils cut documentation at: http://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dcommitdiff;h=3D38cdb0= 1 thanks, P=E1draig. From unknown Wed Jun 18 00:17:16 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 11 Feb 2013 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator