本文介绍了两个文本文件的内连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望对两个不同的文本文件执行内部联接.基本上,我正在寻找与 GNU 连接程序等效的内部连接.这样的事情存在吗?如果没有,awk
或 sed
解决方案将是最有帮助的,但我的首选是 Linux 命令.
Looking to perform an inner join on two different text files. Basically I'm looking for the inner join equivalent of the GNU join program. Does such a thing exist? If not, an awk
or sed
solution would be most helpful, but my first choice would be a Linux command.
这是我想要做的一个例子
Here's an example of what I'm looking to do
文件 1:
0|Alien Registration Card LUA|Checklist Update
1|Alien Registration Card LUA|Document App Plan
2|Alien Registration Card LUA|SA Application Nbr
3|Alien Registration Card LUA|tmp_preapp-DOB
0|App - CSCE Certificate LUA|Admit Type
1|App - CSCE Certificate LUA|Alias 1
2|App - CSCE Certificate LUA|Alias 2
3|App - CSCE Certificate LUA|Alias 3
4|App - CSCE Certificate LUA|Alias 4
文件 2:
Alien Registration Card LUA
结果:
0|Alien Registration Card LUA|Checklist Update
1|Alien Registration Card LUA|Document App Plan
2|Alien Registration Card LUA|SA Application Nbr
3|Alien Registration Card LUA|tmp_preapp-DOB
推荐答案
file2 不应该在末尾包含 LUA
吗?
Should not the file2 contain LUA
at the end?
如果是,您仍然可以使用join
:
If yes, you can still use join
:
join -t'|' -12 <(sort -t'|' -k2 file1) file2
这篇关于两个文本文件的内连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!