From unknown Sat Jun 21 03:21:13 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6394: Is it possible to reorder fields with cut? Resent-From: Peng Yu Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 10 Jun 2010 16:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 6394 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 6394@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.127618909518848 (code B ref -1); Thu, 10 Jun 2010 16:59:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Jun 2010 16:58:15 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMl54-0004tt-5j for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:58:15 -0400 Received: from mail.gnu.org ([199.232.76.166] helo=mx10.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMl51-0004to-Es for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:58:12 -0400 Received: from lists.gnu.org ([199.232.76.165]:39891) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OMl4w-0004YV-T1 for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:58:06 -0400 Received: from [140.186.70.92] (port=56787 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMl4u-0000fY-Am for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:58:06 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID, T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OMl4s-0003KP-B7 for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:58:04 -0400 Received: from mail-yx0-f169.google.com ([209.85.213.169]:54467) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMl4s-0003K7-6m for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:58:02 -0400 Received: by yxs7 with SMTP id 7so53573yxs.0 for ; Thu, 10 Jun 2010 09:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=1/31rx3qkG7U1Tw4+SJDPO2CZ4AzRlGXGym8B98qwSc=; b=hafkkZXOpw04LvOqMJs7Eg1BYe1OMq/Zlk3CHbbk37S8EwBI8N2z06Eq9eU8DStj+U mjPwU5uTd6LF8biLsqs9qksYiLAJJEwu1HrlB0JFAc9DqYB5dYEy5NF9gyf9v45k9YeR gq4DNaMi07IK0nrfnDAugGtPTW+BbU6fB0djc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=KzenyMZ5qyktLoDtmAF22tK3Mw6pWEHO0tuxBeIZ5wp3qbHqa21R2t4LMKznHzaQUn x5qvkBsCZaUtw+TQ9TUxlPmHgkTaVoDwPMXRLttnR/q93GDJrw35QGP7qVYQaXa44rIK WHq2JHrcq7bkcaBIzRkFIxbMjp4aVVIb8bxuw= MIME-Version: 1.0 Received: by 10.150.175.12 with SMTP id x12mr1720363ybe.195.1276189080524; Thu, 10 Jun 2010 09:58:00 -0700 (PDT) Received: by 10.151.26.11 with HTTP; Thu, 10 Jun 2010 09:58:00 -0700 (PDT) Date: Thu, 10 Jun 2010 11:58:00 -0500 Message-ID: From: Peng Yu Content-Type: text/plain; charset=ISO-8859-1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.6 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 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.6 (-----) Hi, I need to reorder the fields in a file. But the -f option can not be used to reorder field 1 and field 2. Basically, I want the original 1st field as the new 2nd field and the original 2nd field the first. Is reordering fields possible with cut. $ cat input.txt a b c e f g $ cut -f 1,2 input.txt a b e f $ cut -f 2,1 input.txt a b e f -- Regards, Peng From unknown Sat Jun 21 03:21:13 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6394: Is it possible to reorder fields with cut? Resent-From: Eric Blake Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 10 Jun 2010 17:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6394 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Peng Yu Cc: 6394@debbugs.gnu.org Received: via spool by 6394-submit@debbugs.gnu.org id=B6394.127619190420286 (code B ref 6394); Thu, 10 Jun 2010 17:46:02 +0000 Received: (at 6394) by debbugs.gnu.org; 10 Jun 2010 17:45:04 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMloN-0005H9-Tl for submit@debbugs.gnu.org; Thu, 10 Jun 2010 13:45:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMloL-0005GZ-Kk for 6394@debbugs.gnu.org; Thu, 10 Jun 2010 13:45:02 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5AHit5n003524 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Jun 2010 13:44:56 -0400 Received: from [10.11.11.199] (vpn-11-199.rdu.redhat.com [10.11.11.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5AHisYN007216; Thu, 10 Jun 2010 13:44:55 -0400 Message-ID: <4C11247D.6030507@redhat.com> Date: Thu, 10 Jun 2010 11:44:29 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4 MIME-Version: 1.0 References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig9E9C3EFFE9A740BF1EC99CB3" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Spam-Score: -10.1 (----------) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 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: -10.1 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig9E9C3EFFE9A740BF1EC99CB3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 06/10/2010 10:58 AM, Peng Yu wrote: > Hi, >=20 > I need to reorder the fields in a file. But the -f option can not be > used to reorder field 1 and field 2. Correct. POSIX standardized this behavior because some scripts rely on it, even though it may not be the most intuitive. >=20 > Basically, I want the original 1st field as the new 2nd field and the > original 2nd field the first. Is reordering fields possible with cut. No. Use awk instead. --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enig9E9C3EFFE9A740BF1EC99CB3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMESR9AAoJEKeha0olJ0NqcJkH/Awn2YhGE5EP+pHOXEyILJDc fvF3ox3zziR0jqRdQqPk/qZ/v+HefDx4A5ZCSK3MQj4GNTtw/crI+/evAT/uVpmv skKdK5ZtVc5taH4S+JHArPoHWvSo3Ntd7ugzvc/hbTpkrdMnMrDZt/YK5rfC6zlX XjUfexntkrII08k4uoi3EAO8YtxyttnotWC7KyvAIa/MVz5C9OeNnZ/ZP+YSl9pW lEnkG91I3GLg7dSzW6cBDyVugA5qb28gf6NtlnPmsZd4fsEQuGSfDY7MtUr/U+fl fna+2i+Rdm+W1aYJIytnwIPYF2af2/JV7Eo1owBv9OhT5qIAZXQb++Of66u5wT0= =QroV -----END PGP SIGNATURE----- --------------enig9E9C3EFFE9A740BF1EC99CB3-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 14 12:31:41 2010 Received: (at control) by debbugs.gnu.org; 14 Jul 2010 16:31:41 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OZ4s1-0008P5-3f for submit@debbugs.gnu.org; Wed, 14 Jul 2010 12:31:41 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OZ4rz-0008P0-Gr for control@debbugs.gnu.org; Wed, 14 Jul 2010 12:31:39 -0400 Received: (qmail 6717 invoked from network); 14 Jul 2010 16:31:47 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 14 Jul 2010 16:31:47 -0000 Message-ID: <4C3DE625.50805@draigBrady.com> Date: Wed, 14 Jul 2010 17:30:29 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: control@debbugs.gnu.org X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -1.8 (-) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 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: -1.8 (-) tags 6394 notabug close 6394 From debbugs-submit-bounces@debbugs.gnu.org Tue Sep 20 14:02:48 2011 Received: (at control) by debbugs.gnu.org; 20 Sep 2011 18:02:49 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1R64eb-0001p9-T6 for submit@debbugs.gnu.org; Tue, 20 Sep 2011 14:02:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1R64eZ-0001oz-G0 for control@debbugs.gnu.org; Tue, 20 Sep 2011 14:02:44 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8KHvYbC030356 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Sep 2011 13:57:35 -0400 Received: from [10.3.113.135] (ovpn-113-135.phx2.redhat.com [10.3.113.135]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p8KHvYB7029741 for ; Tue, 20 Sep 2011 13:57:34 -0400 Message-ID: <4E78D40E.9060006@redhat.com> Date: Tue, 20 Sep 2011 11:57:34 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.22) Gecko/20110906 Fedora/3.1.14-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.14 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: another try Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Spam-Score: -10.3 (----------) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 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: -10.3 (----------) unarchive 6394 forcemerge 6394 9507 thanks -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 13 21:09:39 2013 Received: (at control) by debbugs.gnu.org; 14 Jan 2013 02:09:39 +0000 Received: from localhost ([127.0.0.1]:58925 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TuZUY-0004cQ-9f 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: control 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.