我有两个文件,aa和bb:
$ cat aa
84 xxx
85 xxx
10101 sdf
10301 23
$ cat bb
82 asd
83 asf
84 asdfasdf
10101 22232
10301 llll
Run Code Online (Sandbox Code Playgroud)
我使用join命令加入它们:
$ join aa bb
84 xxx asdfasdf
Run Code Online (Sandbox Code Playgroud)
但预计84,10101和10301都加入了.为什么只有84人加入?
使用词典排序而不是数字排序.
要在此过程中执行此操作:
$ join <(sort aa) <(sort bb)
Run Code Online (Sandbox Code Playgroud)
这给出了输出:
10101 sdf 22232
10301 23 llll
84 xxx asdfasdf
Run Code Online (Sandbox Code Playgroud)
您未能包含输出错误消息的事实:
$ join aa bb
join: file 2 is not in sorted order
84 xxx asdfasdf
join: file 1 is not in sorted order
Run Code Online (Sandbox Code Playgroud)
您可以使用正常的词典排序:
join <(sort aa) <(sort bb) | sort -k1,1n
Run Code Online (Sandbox Code Playgroud)