I notice that join doesn't warn about disorder
when there are no mismatches between the two files,
which is a good thing.

$ join -a1 <(printf '1\n0\n') <(printf '1\n0\n')
1
0

However it does warn if there is no input
in one of the files. I'm inclined to think that
the following should be treated as above?

$ join -a1 <(printf '1\n0\n') /dev/null
1
join: file 1 is not in sorted order
0

Doing that would allow one to use join to
extract fields with awk like blank handling,
and reordering support, without needing
to specify --nocheck-order.

$ printf "1 2 3\n" | join -a1 - /dev/null -o 1.3,1.1
3 1

cheers,
Pádraig.
diff --git a/src/join.c b/src/join.c
index afda5a1..8fcd47b 100644
--- a/src/join.c
+++ b/src/join.c
@@ -354,7 +354,7 @@ keycmp (struct line const *line1, struct line const *line2,
 
 /* Check that successive input lines PREV and CURRENT from input file
    WHATFILE are presented in order, unless the user may be relying on
-   the GNU extension that input lines may be out of order if no input
+   the extension that input lines may be out of order if no input
    lines are unpairable.
 
    If the user specified --nocheck-order, the check is not made.
@@ -711,7 +711,7 @@ join (FILE *fp1, FILE *fp2)
         seq2.count = 0;
     }
 
-  /* If the user did not specify --check-order, then we read the
+  /* If the user did not specify --nocheck-order, then we read the
      tail ends of both inputs to verify that they are in order.  We
      skip the rest of the tail once we have issued a warning for that
      file, unless we actually need to print the unpairable lines.  */
@@ -726,7 +726,8 @@ join (FILE *fp1, FILE *fp2)
     {
       if (print_unpairables_1)
         prjoin (seq1.lines[0], &uni_blank);
-      seen_unpairable = true;
+      if (seq2.count)
+        seen_unpairable = true;
       while (get_line (fp1, &line, 1))
         {
           if (print_unpairables_1)
@@ -740,7 +741,8 @@ join (FILE *fp1, FILE *fp2)
     {
       if (print_unpairables_2)
         prjoin (&uni_blank, seq2.lines[0]);
-      seen_unpairable = true;
+      if (seq1.count)
+        seen_unpairable = true;
       while (get_line (fp2, &line, 2))
         {
           if (print_unpairables_2)

Reply via email to