join: Not everything is perfect

Some of the more elegant tools in coreutils — like comm, sort or uniq — are fairly straightforward and easy to understand.

join, on the other hand, seems to require some inspection. In its simplest form, it makes sense:


Each line from each file is paired and output together. But here’s where things get complicated … or at least my brain wants to follow a different track:


One file is a line longer, so join refuses to join them, or will only join the ones that match. My logic tells me it should join them anyway, but use some sort of placeholder to show information is missing.

If I ask for an additional line with the -a flag, I get the last line but it’s pressed to the left — and you can see how that makes it look like that line belongs to the first list. And the -a flag seems cumbersome, since it requires me to know beforehand that one list or the other is missing data.

And finally … if the lines aren’t prefixed, join shows nothing for its efforts. If they’re not sorted, the unsorted lines are spat out with a warning, in the center of everything else that worked. It’s a bit of a mess.


I understand how join works and I can abide by its rules and formatting, but it seems counterintuitive to me. Perhaps if I just want corresponding lines of two different files output on the same line, there’s another tool I should consider.

For what I’ve seen, join can do that, but it will take a little preparation from me. 😕

5 thoughts on “join: Not everything is perfect

  1. Pingback: Links 23/8/2014: | Techrights

  2. darkstarsword

    Looks like it might be useful if you were trying to use sets or zip (as in functional programming, not the compression tool) from a shell script, but really if you have got to a point where you need functional programming or sets, you really shouldn’t be using shell – Python would be a much better choice.

  3. Pingback: seq: Count up, count down | Inconsolation

  4. Pingback: paste: What I thought join would be | Inconsolation

  5. Pingback: paste: What I thought join would be | Linux Admins

Comments are closed.