加入声明省略条目 [英] Join Statement omitting entries

查看:121
本文介绍了加入声明省略条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用: 的Unix 2.6.18-194.el5

Using: Unix 2.6.18-194.el5

我遇到一个问题,该联接语句从匹配项中忽略了值/索引.我发现值在11-90之间(在大约350万个条目中),并且我尝试查找外来字符,但是我可能会忽略某些内容(尝试使用cat -v来查看隐藏的字符).

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).

这是我正在使用的join语句(为安全起见,仅简化了输出列):

Here is the join statement I am using (only simplified the output columns for security):

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

file1的内容(前20个值):

file1 contents (first 20 values):

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的内容(前50个值,因此您可以看到它的匹配位置)

file2 contents (first 50 values so you can see where it would match):

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

从我的初步测试看来,file2是罪魁祸首.因为当我创建一个值为1-100的新文件时,我可以使join语句与file1完全匹配;但是同一文件将与file2不匹配.

From my initial testing it appears that file2 is the culprit. Because when I create a new file with values 1-100 I am able to get the join statement to match completely against file1; however the same file will not match against file2.

另一个奇怪的是,该文件的长度为350万条记录,它们的值达到90时,它们又开始重新匹配.例如,fileJoined的输出如下所示(仅前20个值):

Another strange thing is that the file is 3.5 million records long and at value 90 they start matching again. For example, the output of fileJoined looks like this (first 20 values only):

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. 使用vi手动输入新行11(在join语句上仍然不匹配)
  2. 将代码复制到记事本中,删除vi中的行,然后将它们复制回(相同的结果,没有匹配的11-90)
  3. 删除11-90行以查看问题是否转移到90-170且没有转移

我认为可能缺少一些隐藏的值,或者file1中的11-90与file2中的11-90与二进制等效吗?

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?

我在这里迷路了,任何帮助将不胜感激.

I am lost here, any help would be greatly appreciated.

推荐答案

我尝试了一下,发现了两件事.

I tried this out, and I noticed a couple things.

首先:这是次要的,但是我认为您在-o说明符中缺少逗号.我将其更改为-o 1.1,2.1.

First: this is minor, but I think you're missing a comma in your -o specifier. I changed it to -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

我认为这是因为join假定按字母顺序排序,而您的输入文件看起来像是按数字排序的.

I think this is because join assumes alphabetical sorting, while your input files look like they're numerically sorted.

join(1)的规则#1是要确保您的输入已排序,并且join期望它们的输入方式相同!

Rule #1 of join(1) is to make sure your inputs are sorted, and the same way join expects them to be!

当我对两个输入文件进行排序并再次加入时,我得到了18行输出. (排序很容易,因为您要加入第一列;我不必弄乱sort的列说明符.)

When I ran the two input files through sort and then joined again, I got 18 rows of output. (Sorting was easy, since you're joining on the first column; I didn't have to muck around with sort's column specifiers.)

请注意,由于语言环境的问题,如今,排序并不总是按照您期望的方式排序.我倾向于设置LC_ALL = C以确保我得到了我惯用的老式行为.

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.

这篇关于加入声明省略条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆