Print specific columns in a matrix on the basis of sample id's in the header I have a matrix file (expression.txt) in which the first column is a gene_id and from the second column the sample id's start. This matrix has 20,000 columns with sample id's corresponding to different tissue. I want to extract the samples of one tissue. Example:  SM-5GZZ7 SM-5GIEN SM-5EGGH are samples from brain tissue. So I want to separate the list of samples [(file=brain.txt;n=5000] corresponding to brain tissue from this matrix (with bash or R)
Name    SM-5GZZ7    SM-5EGHI    SM-5EGHJ    SM-5N9CS    SM-5GIEN    SM-5EGHH    SM-5EGGH
ENSG00000223972.5   0   0   0   0   0   0   0
ENSG00000227232.5   187 109 143 251 113 139 199
ENSG00000278267.1   0   0   1   0   0   0   0
ENSG00000243485.5   1   0   0   1   0   0   0
ENSG00000237613.2   0   0   0   0   0   0   0
ENSG00000268020.3   0   1   0   0   0   1   1

The file brain.txt looks like (Number of lines in this files = 5000)
SM-5GZZ7
SM-5GIEN 
SM-5EGGH
SM-5GZXC
SM-5GZXO
SM-5GZY1
SM-5EGHK
SM-5EGHL
There's a million different ways to do simple taks like this. Pick one and learn it:) Python is my go to as it can do pretty much everything you'd ever want. I saved your example as csv with no spaces called expression.txt.
import pandas as pd
df = pd.read_csv('expression.txt')
df[['SM-5GZZ7','SM-5GIEN','SM-5EGGH']]

SM-5GZZ7    SM-5GIEN    SM-5EGGH
0   0   0.0 0.0
1   187 109 143 251 113 139 199 NaN NaN
2   0   0.0 0.0
3   1   0.0 0.0
4   0   0.0 0.0
5   0   0.0 1.0