summaryrefslogtreecommitdiff
path: root/usr.bin/join
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2017-06-22 02:19:39 +0000
committerConrad Meyer <cem@FreeBSD.org>2017-06-22 02:19:39 +0000
commit34525108904ee22856eddc76e99ad88327e1da68 (patch)
treea3705d69c04851961cfc0b04840e9b99ff6496d0 /usr.bin/join
parent1f7d7cd76af02d7abdcaf81026412f67ab89d426 (diff)
downloadsrc-test-34525108904ee22856eddc76e99ad88327e1da68.tar.gz
src-test-34525108904ee22856eddc76e99ad88327e1da68.zip
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
Notes
Notes: svn path=/head/; revision=320210
Diffstat (limited to 'usr.bin/join')
-rw-r--r--usr.bin/join/join.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/join/join.c b/usr.bin/join/join.c
index 0e66338a80a85..f7906a931f21c 100644
--- a/usr.bin/join/join.c
+++ b/usr.bin/join/join.c
@@ -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");