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?

link|improve this question

feedback

2 Answers

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
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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