Skip to main content
3 of 4
added 67 characters in body
Stéphane Chazelas
  • 585.2k
  • 96
  • 1.1k
  • 1.7k

GNU coreutils includes the command join that does exactly what you want if the line sorting in the result is irrelevant:

join <(sort file1) <(sort file2)

A 1 9
B 3 3
C 1 2

If you want the tabs back, do:

join <(sort file1) <(sort file2) | tr ' ' '\t'

A   1   9
B   3   3
C   1   2

Or use the t option to join.

(<() aka process substitution, requires ksh93 (where the feature originated in), bash or zsh)

jaume
  • 1.3k
  • 13
  • 9