I have two text tables as below:
file1.txt
1 A a
2 B b
3 C c
4 D d
file2.txt
A x i
C z iii
D w iiii
B y ii
I want to have
final.txt
1 A a x i
2 B b y ii
3 C c z iii
4 D d w iiii
I have two text tables as below:
file1.txt
1 A a
2 B b
3 C c
4 D d
file2.txt
A x i
C z iii
D w iiii
B y ii
I want to have
final.txt
1 A a x i
2 B b y ii
3 C c z iii
4 D d w iiii
join -12
= file 1 column 2 (ABCD),-21
= file 2 column 1 (ABCD)-o
= output,2.3
= file 2, column 3.This can be scripted in Python:
Works as so:
You can create final.txt with shell redirection operator
./merge.py file1.txt file2.txt > final.txt
If you have
sqlite3
installed and the two files are the same length you can script that in SQL since table field joins are exactly what SQL is designed to do:Which works as so:
Note that original files shouldn't have trailing newlines, otherwise there will be errors thrown by SQLite.