I have file 1:
sample_1 group_1
sample_2 group_1
sample_3 group_1
sample_4 group_2
sample_5 group_2
sample_6 group_2
sample_7 group_3
sample_8 group_3
sample_9 group_3
and file 2:
sample_8 group_3.1
sample_9 group_3.1
I want to replace the rows in column 2, file 1 with the matching rows of file 2, column 1, so the result is:
sample_1 group_1
sample_2 group_1
sample_3 group_1
sample_4 group_2
sample_5 group_2
sample_6 group_2
sample_7 group_3
sample_8 group_3.1
sample_9 group_3.1
The nearest I have got is to do a left join:
join -a1 -j 1 -o 1.1,1.2,2.2 <(sort -k1 file_1) <(sort -k1 file_2)
which gives me:
sample_1 group_1
sample_2 group_1
sample_3 group_1
sample_4 group_2
sample_5 group_2
sample_6 group_2
sample_7 group_3
sample_8 group_3 group_3.1
sample_9 group_3 group_3.1
Then I thought I could drop the second column if the file 1 second column was repeated in the third column, but of course this does not happen.