Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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
share|improve this answer
    
I can't read man pages correctly, thanks. – pythonic metaphor Aug 9 '11 at 15:44

You must log in to answer this question.

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