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

For example:

file a:

Tom:black
Lily:pink

file b:

Tom:big
Kate:small

And, the result:

join -t: a1 a b

Got:

Tom:black:big
Lily:pink

But what I want is:

Tom:black:big
Lily::pink

i.e. The colon in the last line is missing, any idea?

share|improve this question
up vote 1 down vote accepted

I would think you'd want the fields to be in a consistent position. If so then one of these would work using only one invocation of join and no sed:

$ join -t: -a1 -o 1.1,1.2,2.2 a b
Tom:black:big
Lily:pink:
$ join -t: -a1 -o 1.1,2.2,1.2 a b
Tom:big:black
Lily::pink
share|improve this answer

This behavior is expected per man join:

   -a FILENUM
          print unpairable lines coming from file FILENUM, where FILENUM is 1 or 2, corresponding to FILE1 or FILE2

You can do it in two passes like this:

join -t: a b && join -t: -v1 a b|sed 's/:/::/'

or something along those lines.

share|improve this answer

You must log in to answer this question.

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