0

I need to merge two .csv tables,

one that contains the following info with NO HEADER:

gene0   ABCD
gene1   xyz
gene2   1234

..etc

Another table has a header and information like that:

gene_id sample1
gene0   135
gene1   5468
gene2   65

... etc

What I would like to have is

gene_id sample1
ABCD    135
xyz     5468
1234    65

Is it even possible to merge these two and, if yes, what is the best way to do it?

  • 1
    Are those "genes" always come in consecutive order? – RomanPerekhrest Dec 2 '19 at 18:47
0

For the case when all "genes" come in consecutive order:
one-line combination of head + tail + join commands:

head -1 file2.csv ; join --header -j1 -o1.2,2.2 file1.csv <(tail +2 file2.csv)

Sample output:

gene_id sample1
ABCD 135
xyz 5468
1234 65

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.