简体   繁体   English

linux中的join命令表示文件没有排序,但它们是

[英]join command in linux says that files aren't sorted but they are

I have 2 files, I want to join them. 我有2个文件,我想加入他们。 they are both sorted. 它们都是有序的。 I sorted them by these commands: 我按照以下命令对它们进

$sort -n -k1,1 f1 > t1
$echo $?
0
$mv t1  f1
$sort -n -k1,1 f2 > t1
$echo $?
0
$mv t1 f2

now I run the join command 现在我运行join命令

$join -1 1 -2 1 f1 f2 > fjoin
$echo $?
1

It says those files aren't sorted 它说这些文件没有排序

$cat f1
0 0
5 0
9 0
10 0 <----- problem is here
$cat f2
0 1
3 1
11 2 <----- problem is here

I suggest to remove sort's option -n . 我建议删除sort的选项-n

From man join : man join

Important: FILE1 and FILE2 must be sorted on the join fields. 要点:必须在连接字段上对FILE1和FILE2进行排序。 Eg, use sort -k 1b,1 if join has no options, or use join -t '' if sort has no options. 例如,使用sort -k 1b,1如果join已经没有选择,或者使用join -t ''如果sort没有选项。 Note, comparisons honor the rules specified by LC_COLLATE . 注意,比较遵循LC_COLLATE指定的规则。 If the input is not sorted and some lines cannot be joined, a warning message will be given. 如果输入未排序且某些行无法连接,则会给出警告消息。

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

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