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?

link|improve this question

feedback

1 Answer

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

Your Answer

 
or
required, but never shown

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