From 4e3ba9af0dd7c08a2c003dbd3019b64758d456f1 Mon Sep 17 00:00:00 2001 From: eadler Date: Mon, 19 Mar 2018 03:22:43 +0000 Subject: MFC r320210: 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 --- usr.bin/join/join.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/join/join.c b/usr.bin/join/join.c index 74f7dc7..63dccb7 100644 --- a/usr.bin/join/join.c +++ b/usr.bin/join/join.c @@ -469,9 +469,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"); -- cgit v1.1