Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Jun 2017 02:19:40 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r320210 - head/usr.bin/join
Message-ID:  <201706220219.v5M2Jet6060770@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Thu Jun 22 02:19:39 2017
New Revision: 320210
URL: https://svnweb.freebsd.org/changeset/base/320210

Log:
  join(1): Fix field ordering for -v output
  
  Per POSIX, join(1) (in modes other than -o) is a concatenation of selected
  character fields.  The joined field is first, followed by fields in the
  order they occurred in the input files.
  
  Our join(1) utility previously handled this correctly for lines with a match
  in the other file.  But it failed to order output fields correctly for
  unmatched lines, printed in -a and -v modes.
  
  A simple test case is:
  
  $ touch a
  $ echo "2 1" > b
  $ join -v2 -2 2 a b
  1 2
  
  PR:		217711
  Reported by:	alt.j2-4o4s2yon at yopmail.com
  Sponsored by:	Dell EMC Isilon

Modified:
  head/usr.bin/join/join.c

Modified: head/usr.bin/join/join.c
==============================================================================
--- head/usr.bin/join/join.c	Thu Jun 22 01:11:20 2017	(r320209)
+++ head/usr.bin/join/join.c	Thu Jun 22 02:19:39 2017	(r320210)
@@ -467,9 +467,15 @@ outoneline(INPUT *F, LINE *lp)
 			else
 				outfield(lp, 0, 1);
 		}
-	else
+	else {
+		/*
+		 * Output the join field, then the remaining fields.
+		 */
+		outfield(lp, F->joinf, 0);
 		for (cnt = 0; cnt < lp->fieldcnt; ++cnt)
-			outfield(lp, cnt, 0);
+			if (F->joinf != cnt)
+				outfield(lp, cnt, 0);
+	}
 	(void)printf("\n");
 	if (ferror(stdout))
 		err(1, "stdout");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201706220219.v5M2Jet6060770>