My solution is not perfect, but it is simple:
join -1 2 -2 1 -o 1.1,1.2,2.2 table1.txt table2.txt
Output
item_ID term_ID term_locator
------- ------- ------------
C051890 C535944 1340
C051890 C535944 1523
C051890 C535944 1829
C051890 C535944 1864
C061133 C535944 1340
C061133 C535944 1523
C061133 C535944 1829
C061133 C535944 1864
C402769 C535944 1340
C402769 C535944 1523
C402769 C535944 1829
C402769 C535944 1864
D000082 C535944 1340
D000082 C535944 1523
D000082 C535944 1829
D000082 C535944 1864
C006632 D017624 1277
C006632 D017624 4290
C051890 D017624 1277
C051890 D017624 4290
Discussion
- The line order is a little different
- You must have the
join
command installed - The flags
-1 2 -2 1
simply says: join file1/column2 with file2/column1 - The flag
-o 1.1,1.2,2.2
says: output file1/column1, file1/column2, and file2/column2 - Based on the command line order, file1=table1.txt, file2=table2.txt