Skip to content
Advertisement

Faster solution to compare files in bash

file1:

JavaScript

and file2:

JavaScript

I need find match file2 in file1 and print whole file1 + second column of file2

So ouptut is:

JavaScript

My solution is very slow in bash:

JavaScript

I am prefer FASTER any bash or awk solution. Output can be modified, but need keep all the informations (order of column can be different).

EDIT:

Right now it looks like fastest solution according @chepner:

JavaScript

Advertisement

Answer

Another solution using join and sed, Under the assumption that file1 and file2 are sorted

JavaScript

If the output order doesn’t matter, to use awk

JavaScript

you get,

chr1 14361 14829 NR_024540_0_r_DDX11L1,WASH7P_468 11
chr1 14969 15038 NR_024540_1_r_WASH7P_69 11
chr1 15795 15947 NR_024540_2_r_WASH7P_152 11
chr1 16606 16765 NR_024540_3_r_WASH7P_15 11
chr1 16857 17055 NR_024540_4_r_WASH7P_198 11
Advertisement