简体   繁体   English

加入声明省略条目

[英]Join Statement omitting entries

Using: Unix 2.6.18-194.el5 使用:Unix 2.6.18-194.el5

I am having an issue where this join statement is omitting values/indexes from the match. 我遇到一个问题,该联接语句从匹配中省略了值/索引。 I found out the values are between 11-90 (out of about 3.5 Million entries) and I have tried to look for foreign characters but I may be overlooking something (Tried cat -v to see hidden characters). 我发现值在11-90之间(在大约350万个条目中),并且我尝试查找外来字符,但是我可能忽略了某些内容(尝试使用cat -v来查看隐藏的字符)。

Here is the join statement I am using (only simplified the output columns for security): 这是我正在使用的join语句(为安全起见,仅简化了输出列):

join -t "|" -j 1 -o 1.1 2.1 file1 file2> fileJoined

file1 contents (first 20 values): file1的内容(前20个值):

1 3 7 11 12 16 17 19 20 21 27 28 31 33 34 37 39 40 41 42 1 3 7 11 12 16 17 19 20 21 27 28 31 33 34 37 39 40 41 42

file2 contents (first 50 values so you can see where it would match): file2内容(前50个值,因此您可以看到它的匹配位置):

1|US 2|US 3|US 4|US 5|US 6|US 7|US 8|US 9|US 10|US 11|US 12|US 13|US 14|US 15|US 16|US 17|US 18|US 19|US 20|US 21|US 22|US 23|US 24|US 25|US 26|US 27|US 28|US 29|US 30|US 31|US 32|US 33|US 34|US 35|US 36|US 37|US 38|US 39|US 40|US 41|US 42|US 43|US 44|US 45|US 46|US 47|US 48|US 49|US 50|US 1 | US 2 | US 3 | US 4 | US 5 | US 6 | US 7 | US 8 | US 9 | US 10 | US 11 | US 12 | US 13 | US 14 | US 15 | US 16 | US 17 | US 18 | US 19 | US 20 | US 21 | US 22 | US 23 | US 24 | US 25 | US 26 | US 27 | US 28 | US 29 | US 30 | US 31 | US 32 | US 33 | US 34 | US 35 | US 36 | US 37 | US 38 | US 39 | US 40 | US 41 | US 42 | US 43 | US 44 | US 45 | US 46 | US 47 | US 48 | US 49 | US 50 | US

From my initial testing it appears that file2 is the culprit. 从我的初步测试看来,file2是元凶。 Because when I create a new file with values 1-100 I am able to get the join statement to match completely against file1; 因为当我创建一个值为1-100的新文件时,我能够使join语句与file1完全匹配。 however the same file will not match against file2. 但是,同一文件将与file2不匹配。

Another strange thing is that the file is 3.5 million records long and at value 90 they start matching again. 另一个奇怪的是,该文件的长度为350万条记录,并且在值90时它们再次开始匹配。 For example, the output of fileJoined looks like this (first 20 values only): 例如,fileJoined的输出如下所示(仅前20个值):

1|1 3|3 7|7 90|90 91|91 92|92 93|93 95|95 96|96 97|97 98|98 99|99 106|106 109|109 111|111 112|112 115|115 116|116 117|117 118|118 1 | 1 3 | 3 7 | 7 90 | 90 91 | 91 92 | 92 93 | 93 95 | 95 96 | 96 97 | 97 98 | 98 99 | 99 106 | 106 109 | 109 111 | 111 112 | 112 115 | 115 116 | 116 117 | 117 118 | 118

Other things I have tried are: 我尝试过的其他事情是:

  1. Using vi to manually enter a new line 11 (still doesnt match on the join statement) 使用vi手动输入新行11(join语句上仍然不匹配)
  2. copying the code into notepad, deleting the lines in vi and then copying them back in (same result, no matching 11-90) 将代码复制到记事本中,删除vi中的行,然后将它们复制回(相同的结果,没有匹配的11-90)
  3. Removing lines 11-90 to see if the problem then shifts to 90-170 and it does not shift 删除第11-90行以查看问题是否转移到90-170且没有转移

I think that there may be some hidden values that I am missing, or that the 11 - 90 from file1 is not the same binary equivalent as the 11 - 90 in file2? 我认为可能缺少一些隐藏值,或者file1中的11-90与file2中的11-90不是相同的二进制等效项?

I am lost here, any help would be greatly appreciated. 我在这里迷路了,任何帮助将不胜感激。

I tried this out, and I noticed a couple things. 我尝试了一下,然后发现了几件事。

First: this is minor, but I think you're missing a comma in your -o specifier. 首先:这是次要的,但是我认为您在-o指示符中缺少逗号。 I changed it to -o 1.1,2.1 . 我将其更改为-o 1.1,2.1

But then, running it on just the fragments you posted, I got only three lines of output: 但是,仅在您发布的片段上运行它,我只有三行输出:

1|1
3|3
7|7

I think this is because join assumes alphabetical sorting, while your input files look like they're numerically sorted. 我认为这是因为join假定按字母顺序排序,而您的输入文件看起来像按数字排序。

Rule #1 of join(1) is to make sure your inputs are sorted, and the same way join expects them to be! join(1)的规则#1是要确保您的输入已排序,并且join期望它们的方式相同!

When I ran the two input files through sort and then joined again, I got 18 rows of output. 当我对两个输入文件进行排序并再次加入时,我得到了18行输出。 (Sorting was easy, since you're joining on the first column; I didn't have to muck around with sort's column specifiers.) (排序很容易,因为您要加入第一列;我不必弄乱sort的列说明符。)

Beware that, these days, sort doesn't always sort the way you expect, due to locale issues. 请注意,由于区域设置的问题,如今,排序并不总是按照您期望的方式排序。 I tend to set LC_ALL=C to make sure I get the old-fashioned behavior I'm used to. 我倾向于设置LC_ALL = C,以确保得到我惯用的老式行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM