Wednesday, August 09, 2006

Linux:: join

How to join files, which have a common key?
Example :

File t1 :


Row Search Number_Hit
1. Lieberman 60853
2. Adnan Hajj 40642
3. Icalendar 30674
4. Meebo 26389
5. Lamont 26321
6. Buffett 25321
7. Video 19532
8. Aol Search 18344
9. Lebanon 16532
10. Israel 15342
11. Wwdc 11453
12. Cynthia 10567
13. McKinney 9674
14. Ned Lamont 8334
15. Photo 7653

File t2 :

Row Tags
1. Israel
2. Lebanon
3. War
4. Hezbollah
5. lieberman
5. Microsoft
6. leberman
7. AOL
8. ned lamont
9. wordpress
10. Windows
11. Iraq
12. Sex
13. Bush
14. Middle
To compare and join the key 2 of the file 1 (this is the signification of the argument -1 2)
with the key 1 of the file 2.

$ join -1 1 -2 1 techno_1 techno_2

Row Search Number_Hit Tags
1. Lieberman 60853 Israel
2. Adnan Hajj 40642 Lebanon
3. Icalendar 30674 War
4. Meebo 26389 Hezbollah
5. Lamont 26321 lieberman
5. Lamont 26321 Microsoft
6. Buffett 25321 leberman
7. Video 19532 AOL
8. Aol Search 18344 ned lamont
9. Lebanon 16532 wordpress
10. Israel 15342 Windows
11. Wwdc 11453 Iraq
12. Cynthia 10567 Sex
13. McKinney 9674 Bush
14. Ned Lamont 8334 Middle
Interesting isn'it?
I hope it could help you, in fact this is not the best example, I know but if you were seqrching how to concatenate two files this is the tool you need, and I've just give you the syntax. I hope it will be helpful

1 comment:

Sherman Boyd said...

Real nice!