summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2011-01-27 07:17:16 +0000
committerPádraig Brady <P@draigBrady.com>2011-01-29 23:39:16 +0000
commit877ca5bf8588ae73a6ccc672e41f13c5b3943b14 (patch)
treeaecfb3505bf785ccb775305fb49bf89d712b0fa9
parent32626bde6d68508109a99dfe0a089a0025f56085 (diff)
downloadcoreutils-877ca5bf8588ae73a6ccc672e41f13c5b3943b14.tar.xz
join: don't report disorder against an empty file
This allows one to use join as a field extractor like: join -a1 -o 1.3,1.1 - /dev/null * src/join.c (join): Don't flag unpairable lines when one of the files is empty. * tests/misc/join: Add a new test for empty input, and adjust a previous test that was only checking against empty input. * doc/coreutils.texi (join invocation): Document the change. * NEWS: Likewise.
-rw-r--r--NEWS6
-rw-r--r--doc/coreutils.texi18
-rw-r--r--src/join.c8
-rwxr-xr-xtests/misc/join6
4 files changed, 29 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index a042ee016..6e7efe195 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,12 @@ GNU coreutils NEWS -*- outline -*-
output format from the first line in each file, to ensure
the same number of fields are output for each line.
+** Changes in behavior
+
+ join no longer reports disorder when one of the files is empty.
+ This allows one to use join as a field extractor like:
+ join -a1 -o 1.3,1.1 - /dev/null
+
* Noteworthy changes in release 8.9 (2011-01-04) [stable]
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index d6e98c6d6..b89147ea8 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -4787,11 +4787,17 @@ If there is an error it exits with nonzero status.
@macro checkOrderOption{cmd}
If the @option{--check-order} option is given, unsorted inputs will
cause a fatal error message. If the option @option{--nocheck-order}
-is given, unsorted inputs will never cause an error message. If
-neither of these options is given, wrongly sorted inputs are diagnosed
-only if an input file is found to contain unpairable lines. If an
-input file is diagnosed as being unsorted, the @command{\cmd\} command
-will exit with a nonzero status (and the output should not be used).
+is given, unsorted inputs will never cause an error message. If neither
+of these options is given, wrongly sorted inputs are diagnosed
+only if an input file is found to contain unpairable
+@ifset JOIN_COMMAND
+lines, and when both input files are non empty.
+@end ifset
+@ifclear JOIN_COMMAND
+lines.
+@end ifclear
+If an input file is diagnosed as being unsorted, the @command{\cmd\}
+command will exit with a nonzero status (and the output should not be used).
Forcing @command{\cmd\} to process wrongly sorted input files
containing unpairable lines by specifying @option{--nocheck-order} is
@@ -5672,7 +5678,9 @@ c c1 c2
b b1 b2
@end example
+@set JOIN_COMMAND
@checkOrderOption{join}
+@clear JOIN_COMMAND
The defaults are:
@itemize
diff --git a/src/join.c b/src/join.c
index ab7625183..941185c8a 100644
--- a/src/join.c
+++ b/src/join.c
@@ -736,7 +736,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. */
@@ -751,7 +751,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)
@@ -765,7 +766,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)
diff --git a/tests/misc/join b/tests/misc/join
index 5086ee75e..eae3f18a8 100755
--- a/tests/misc/join
+++ b/tests/misc/join
@@ -209,7 +209,11 @@ my @tv = (
# Before 6.10.143, this would mistakenly fail with the diagnostic:
# join: File 1 is not in sorted order
-['chkodr-7', '-12', ["2 a\n1 b\n", ""], "", 0],
+['chkodr-7', '-12', ["2 a\n1 b\n", "2 c\n1 d"], "", 0],
+
+# After 8.9, join doesn't report disorder by default
+# when comparing against an empty input file.
+['chkodr-8', '', ["2 a\n1 b\n", ""], "", 0],
# Test '--header' feature
['header-1', '--header',