bash - 基于特定列的两个文件的交集?
我想要执行以下操作,如果有人可以帮助我完成此操作,我将非常感激:
我有 2 个名为 File1.txt 和 File2.txt 的制表符分隔文件(如下所示)。 如果在 File2.txt 的第三列(整数)中找到 File1.txt 中的第二列(整数),则 我想制作 new_File1.txt 和 new_File2.txt 并继续附加 行。
File1.txt:
1 80 xyc
1 304 xyv
1 813653 xyb
1 813661 xyn
1 954653 xym
File2.txt:
abvb 1 178
aaa 1 304
ttt 1 353
ggg 1 98971
ghj 1 813653
因此,例如我的 new_File1.txt 将如下所示:
new_File1.txt:
1 304 xyv
1 813653 xyb
new_File2.txt :
aaa 1 304
ghj 1 813653
谢谢大家的帮助! 我已经使用了 :
join -1 2 -2 3 -t '\t' file1.txt file2.txt
但它给了我以下输出:
\1 80 xyc\abvb 1 178
\1 80 xyc\aaa 1 304
\1 80 xyc\ttt 1 353
\1 80 xyc\ggg 1 98971
\1 80 xyc\ghj 1 813653
\1 304 xyv\abvb 1 178
\1 304 xyv\aaa 1 304
\1 304 xyv\ttt 1 353
\1 304 xyv\ggg 1 98971
\1 304 xyv\ghj 1 813653
\1 813653 xyb\abvb 1 178
\1 813653 xyb\aaa 1 304
\1 813653 xyb\ttt 1 353
\1 813653 xyb\ggg 1 98971
\1 813653 xyb\ghj 1 813653
\1 813661 xyn\abvb 1 178
\1 813661 xyn\aaa 1 304
\1 813661 xyn\ttt 1 353
\1 813661 xyn\ggg 1 98971
\1 813661 xyn\ghj 1 813653
\1 954653 xym\abvb 1 178
\1 954653 xym\aaa 1 304
\1 954653 xym\ttt 1 353
\1 954653 xym\ggg 1 98971
\1 954653 xym\ghj 1 813653
I want to do the following and would really appreciate if someone can help me accomplish this:
I have 2 tab-delim files named File1.txt and File2.txt(shown below).
If the 2nd column (integer) in File1.txt is found in 3rd column (integer) of File2.txt then
i want to make new_File1.txt and new_File2.txt and keep appending
the rows.
File1.txt:
1 80 xyc
1 304 xyv
1 813653 xyb
1 813661 xyn
1 954653 xym
File2.txt:
abvb 1 178
aaa 1 304
ttt 1 353
ggg 1 98971
ghj 1 813653
So for example my new_File1.txt will look like:
new_File1.txt:
1 304 xyv
1 813653 xyb
new_File2.txt:
aaa 1 304
ghj 1 813653
Thank you all for your help!
I have used :
join -1 2 -2 3 -t '\t' file1.txt file2.txt
but it gives me the following output:
\1 80 xyc\abvb 1 178
\1 80 xyc\aaa 1 304
\1 80 xyc\ttt 1 353
\1 80 xyc\ggg 1 98971
\1 80 xyc\ghj 1 813653
\1 304 xyv\abvb 1 178
\1 304 xyv\aaa 1 304
\1 304 xyv\ttt 1 353
\1 304 xyv\ggg 1 98971
\1 304 xyv\ghj 1 813653
\1 813653 xyb\abvb 1 178
\1 813653 xyb\aaa 1 304
\1 813653 xyb\ttt 1 353
\1 813653 xyb\ggg 1 98971
\1 813653 xyb\ghj 1 813653
\1 813661 xyn\abvb 1 178
\1 813661 xyn\aaa 1 304
\1 813661 xyn\ttt 1 353
\1 813661 xyn\ggg 1 98971
\1 813661 xyn\ghj 1 813653
\1 954653 xym\abvb 1 178
\1 954653 xym\aaa 1 304
\1 954653 xym\ttt 1 353
\1 954653 xym\ggg 1 98971
\1 954653 xym\ghj 1 813653
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找
join(1)
。You're looking for
join(1)
.