32

Is there a Linux command like cat that joins files with the same number of lines horizontally?

  • It took me a LONG time to find this question! It seems "horizontal" is the only way to find an answer to this problem. All the other "duplicates" when I searched for "concatenate columns with awk", etc., only led to database join with awk. – Josiah Yoder Dec 07 '22 at 15:08

2 Answers2

46

paste may do the trick.

% cat t1 
a
b
c
c
d
f
g
% cat t2 
h
i
j
k
l
m
n
% paste t1 t2 
a       h
b       i
c       j
c       k
d       l
f       m
g       n

At least some of the time, you don't need to have a "key" to concatenate the lines.

l0b0
  • 51,350
5

join should do the trick - You just need to prefix the lines with an identical ID.

l0b0
  • 51,350