内连接在两个文本文件 [英] inner join on two text files
本文介绍了内连接在两个文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
展望执行两个不同的文本文件内连接。基本上,我在寻找内部加入了GNU相当于加入计划。难道这样的事情存在吗?如果不是这样,一个awk或sed的解决方案将是最有帮助的,但是我的第一选择将是一个linux命令。
这里是什么我希望做一个例子
文件1:
0 |外国人登记卡LUA |清单更新
1 |外国人登录证LUA |文件应用计划
2 |外国人登录证LUA | SA应用树木包
3 |外国人登录证LUA | tmp_ preAPP-DOB
0 |应用 - 欧安会证书LUA |承认类型
1 |应用 - 欧安会证书LUA |别名1
2 |应用 - 欧安会证书LUA |别名2
3 |应用 - 欧安会证书LUA |别名3
4 |应用 - 欧安会证书LUA |别名4
文件2:
外国人登录证LUA
结果:
0 |外国人登记卡LUA |清单更新
1 |外国人登录证LUA |文件应用计划
2 |外国人登录证LUA | SA应用树木包
3 |外国人登录证LUA | tmp_ preAPP-DOB
解决方案
不应该的文件2包含 LUA
末?
如果是的,你仍然可以使用加入
:
加入-t| -12≤(排序-t'|'-k2文件1)文件2
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
file 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
file 2:
Alien Registration Card LUA
Results:
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
解决方案
Should not the file2 contain LUA
at the end?
If yes, you can still use join
:
join -t'|' -12 <(sort -t'|' -k2 file1) file2
这篇关于内连接在两个文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文