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.
  • 38,596
  • 16
  • 96
  • 104

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
  • 6,522
  • 2
  • 38
  • 52
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
  • 11,964
  • 22
  • 40