我有两个排序文件:
cat file1
1
3
cat file2
C 1 D
B 2 E
A 3 F
我运行以下命令:
join -1 1 -2 2 -v2 file1 file2
在 2008 年 1 月 Debian 4.3.2-1.1 上的 GNU coreutils 6.9.92.4-f088d-dirt 中,我得到:
B 2 E
使用 GNU coreutils 8.12.197-032bb 2011 年 9 月在 Ubuntu 4.4.3-4ubuntu5.1 (Ubuntu precise (12.04.2 LTS)) 我得到:
2 B E
为什么我得到不同的结果?为什么我在任何地方都找不到记录的此更改?以下是两个人输出的内容:
-a FILENUM
print unpairable lines coming from file FILENUM, where FILENUM
is 1 or 2, corresponding to FILE1 or FILE2
-v FILENUM
like -a FILENUM, but suppress joined output lines
以下是我必须做的,以获得每个Linux发行版的相同答案:
join -1 1 -2 2 -v2 -o 2.1,2.2,2.3 file1 file2
我找到了答案。以下是较新版本的信息联接输出的一部分:
`-o auto'
If the keyword `auto' is specified, infer the output format from
the first line in each file. This is the same as the default
output format but also ensures the same number of fields are
output for each line. Missing fields are replaced with the `-e'
option and extra fields are discarded.
Otherwise, construct each output line according to the format in
FIELD-LIST. Each element in FIELD-LIST is either the single
character `0' or has the form M.N where the file number, M, is `1'
or `2' and N is a positive field number.
A field specification of `0' denotes the join field. In most
cases, the functionality of the `0' field spec may be reproduced
using the explicit M.N that corresponds to the join field.
However, when printing unpairable lines (using either of the `-a'
or `-v' options), there is no way to specify the join field using
M.N in FIELD-LIST if there are unpairable lines in both files. To
give `join' that functionality, POSIX invented the `0' field
specification notation.
All output lines--including those printed because of any -a or -v
option--are subject to the specified FIELD-LIST.
谜团解决了,尽管我仍然认为不幸的是,核心 unix 实用程序在版本之间改变了行为。这教会了我在开发新的 Linux 发行版时重新阅读文档。