Increment two files based on specific columns?

I want to do the following and I will be very grateful if someone can help me with this:

I have two tab delimited files named File1.txt and File2.txt (shown below). If the second column (integer) in File1.txt is in the third column (integer) of File2.txt, then I want to make new_File1.txt and new_File2.txt and continue to add lines.

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 this:

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 used:

join -1 2 -2 3 -t '\t' file1.txt file2.txt

but it gives me the following result:

\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
+5
source share
1 answer

You are looking for join(1).

+5

All Articles