2

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?

1 Answer 1

4

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
1
  • @pythonicmetaphor It didn't explicitly mention using -a twice.
    – Geremia
    Sep 9, 2016 at 2:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .