join (pls help on join command)

Hi,

I am a new learner of join command. Some result really make me confused.
Please kindly help me.

input:

file1:
LEO oracle engineer 210375
P.Jones Office Runner ID897
L.Clip Personl Chief ID982
S.Round UNIX admin ID6

file2:
Dept2C ID897 6 years
Dept5Z ID982 1 year
Dept3S ID6 2 years
GEDA 210375 1 year

What i exactly want is:

ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year
ID6 S.Round UNIX admin Dept3S 2 years
210375 LEO oracle engineer GEDA 1 year

Follow is the code and result according to my example. Could anybody explain why the result is not correct. It seems my soaris can only output first two lines(since if i split the input file to four groups, and each group contain only one line, it works ok.)

Thanks in advanced!

code1: join -j1 4 -j2 2 file1 file2
result1:
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year

code2:join -a1 -j1 4 -j2 2 file1 file2
reuslt2:
210375 LEO oracle engineer
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year

code3:
join -a2 -j1 4 -j2 2 file1 file2
reustl3:
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year
ID6 Dept3S 2 years
210375 GEDA 1 year

A quick fix :slight_smile: Hope this works

$ cat fil1
LEO oracle engineer 210375
P.Jones Office Runner ID897
L.Clip Personl Chief ID982
S.Round UNIX admin ID6

$ cat fil2
Dept2C ID897 6 years
Dept5Z ID982 1 year
Dept3S ID6 2 years
GEDA 210375 1 year

$ sort +3 -4 fil1 > fil1.tmp
$ sort +1 -2 fil2 > fil2.tmp

$ join -1 4 -2 2 fil1.tmp fil2.tmp
210375 LEO oracle engineer GEDA 1 year
ID6 S.Round UNIX admin Dept3S 2 years
ID897 P.Jones Office Runner Dept2C 6 years
ID982 L.Clip Personl Chief Dept5Z 1 year