Join fields from files with duplicate lines

view story

http://www.unix.com – I have two files, file1.txt: 1 abc 2 def 2 dgh 3 ijk 4 lmn file2.txt 1 opq 2 rst 3 uvw My desired output is: 1 abc opq 2 def rst 2 dgh rst 3 ijk uvw I have tried using the 'join' command (ie. 'join file1.txt file2.txt') but it returns the error that file1.txt is not sorted because of the repeated value (ie. 2). Does anyone know how to solve this? Thanks! (HowTos)