Author: eadler
Date: Mon Mar 19 03:22:43 2018
New Revision: 331164
URL: https://svnweb.freebsd.org/changeset/base/331164
Log:
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
Modified:
stable/11/usr.bin/join/join.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.bin/join/join.c
==============================================================================
--- stable/11/usr.bin/join/join.c Mon Mar 19 03:20:35 2018
(r331163)
+++ stable/11/usr.bin/join/join.c Mon Mar 19 03:22:43 2018
(r331164)
@@ -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");
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"