summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2018-03-19 03:22:43 +0000
committereadler <eadler@FreeBSD.org>2018-03-19 03:22:43 +0000
commit4e3ba9af0dd7c08a2c003dbd3019b64758d456f1 (patch)
treec5aaf8fc0894ad7f2d22e6cb7ea316f719967e1c /usr.bin
parent78eb5a01e11e41c78876b5cf1d8ffff02f42fefe (diff)
downloadFreeBSD-src-4e3ba9af0dd7c08a2c003dbd3019b64758d456f1.zip
FreeBSD-src-4e3ba9af0dd7c08a2c003dbd3019b64758d456f1.tar.gz
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
Diffstat (limited to 'usr.bin')
-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 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");
OpenPOWER on IntegriCloud