I'm trying to join the two files below:


ABCA1   0   2
ABCA4   3   12
ABCB11  0   4
ABCB4   0   3
ABCC6   0   3
ABCC8   4   33


ABCA4   2
ABCB11  1

Where there isn't a match in the second file I want a 0 printed. I've tried this join command:

join -a 1 -a 2 -e '0' -o 0,1.2,1.3,2.2 FileA.txt FileB.txt

However, this prints 0's for all of the entries in the new 3rd column. As so:

ABCA1 0 2 0
ABCA4 3 12 0
ABCB11 0 4 0
ABCB4 0 3 0
ABCC6 0 3 0

I used a version of this command to generate my FileA.txt. I'm not sure why it won't work to add a third column. Any help?

  • I can't reproduce your output. Using your command and your sample files I see 2 and 1 for the third column for the expected lines Nov 5, 2015 at 14:11
  • @EricRenouf Could it be a problem with my version of join? Nov 5, 2015 at 14:12
  • I suppose it could be, on occasion people have posted working code and tested the wrong thing on their own, so I'd confirm that you are really seeing that result with those files. I have tried it on 3 different flavors of linux myself Nov 5, 2015 at 14:18

1 Answer 1


The behavior of join changes when locale environment variables are set. Try your join after doing export LC_ALL=en_US.UTF-8 or export LC_ALL=C.

  • I ran my command with LC_ALL=C join -a 1 -a 2 -e '0' -o 0,1.2,1.3,2.2 FileA.txt FileB.txt. Should that suffice? Nov 5, 2015 at 15:01
  • @stellar01 - Yes, that should work, if locale is the problem.
    – user732
    Nov 5, 2015 at 15:47
  • Even with the adjustment, I fail to get the appropriate result. I don't understand why it won't work. I was able to successfully use this command a couple months ago, but I can no longer use it now :( I guess I'll switch to awk Nov 5, 2015 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.