Suppose I have two files that look like this:

File 1:

1 x
2 y
3 z
5 l

File 2:

1 a
2 b
4 c
5 c

And I want to join them using the first column as a key to give

1 x a
2 y b
3 z
4 c
5 l c

where a missing line in one file just means that I omit its data. I thought join would do the trick, but it seems to insist on skipping any line that doesn't appear in both files and I can't find an option to make it do otherwise. AT least -e didn't work how I thought it would. What's the right command line way to do this?


This is possible with the join command using the -a option (twice, once for each file number). Example:

join -a1 -a2 1.txt 2.txt
  • @pythonicmetaphor It didn't explicitly mention using -a twice. – Geremia Sep 9 '16 at 2:57

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.