How to extract values from second file on the basis common first column? File1:

ENST00000000233 ARF5
ENST00000000412 M6PR
ENST00000001008 FKBP4
ENST00000001146 CYP26B1
ENST00000002501 DBNDD1
ENST00000002596 HS3ST1


File 2:

ENST00000000412 0.779142
ENST00000001008 0.738143
ENST00000002501 0.715315
ENST00000002596 0.713664


Desired Output

ENST00000000412 0.779142    M6PR
ENST00000001008 0.738143    FKBP4
ENST00000002501 0.715315    DBNDD1
ENST00000002596 0.713664    HS3ST1
I like to use the join command for this. For your example above, you can simply use the following:

$ join file2 file1
ENST00000000412 0.779142 M6PR
ENST00000001008 0.738143 FKBP4
ENST00000002501 0.715315 DBNDD1
ENST00000002596 0.713664 HS3ST1


This assumes your files are sorted. If they aren't sorted, you can use input redirection if your shell supports it (bash and other modern shells do):

join &lt;(sort -k 1b,1 file2) &lt;(sort -k 1b,1 file1)


If your shell doesn't support &lt;(), sort the files first:

sort file1 &gt; file1.sorted; sort file2 &gt; file2.sorted
join &lt;(sort -k 1b,1 file2.sorted) &lt;(sort -k 1b,1 file1.sorted)