2

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?

1

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
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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