0

I need help to align two files by similitude of the values from the column 2 (file 1) and column 1 (file 2).

file 1:

1 d 3
2 e 4 
5 o 1

file 2:

e 6
o 5
d 8

I want to get

1 d 3 d 8
2 e 4 e 6
5 o 1 o 5
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116

2 Answers2

2

Try using the join command:

join -o "1.1,1.2,1.3,2.1,2.2" -1 2 <(cat file1 | sort) <(cat file2 | sort)

output:

1 d 3 d 8
2 e 4 e 6
5 o 1 o 5

Your files will need to be sorted for this to work. They weren't, so I had to sort them for you.

Addison
  • 7,322
  • 2
  • 39
  • 55
0

If both files have exactly the same keys (and number of lines), you can use paste:

paste -d\  <(sort -k2 file1) <(sort file2)
oliv
  • 12,690
  • 25
  • 45