How to extract column from a matrix matching the another file (sample file)
Assuming your &quot;master&quot; files looks like this:
df &lt;- data.frame(Name = LETTERS[1:5],
                 Col1 = sample(1:10,5),
                 Col2 = sample(1:10,5),
                 Col11 = sample(1:10,5),
                 Col3 = sample(1:10,5))

  Name Col1 Col2 Col11 Col3
1    A    5    4     3   10
2    B    1    6     5    6
3    C    3    1     9    4
4    D    9    9     8    9
5    E    8   10     1    1

For a sequence of pattern you want to extract, you can use base r function such as grep:
match_pat = c(&quot;Col1&quot;,&quot;Col2&quot;)

m &lt;- unlist(sapply(match_pat,function(x) grep(x,colnames(df))))

Col11 Col12  Col2 
    2     4     3 

And then, extract your columns of interest by doing:
&gt; df[,m]
  Col1 Col11 Col2
1    5     3    4
2    1     5    6
3    3     9    1
4    9     8    9
5    8     1   10

In your example, it will be something like:
match_pat &lt;- c(&quot;GTEX.1117F&quot;,&quot;GTEX.111FC&quot;,&quot;GTEX.111XS&quot;)
m &lt;- unlist(sapply(match_pat,function(x) grep(x,colnames(df))))

master[,m]
```