Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

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
share|improve this answer
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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