1

I have a file in which the first and second column are individuals ids and the rest are genotype information (I should mention there are TWO rows per individual). this file has a header line but only for the genotype columns, not the first and second columns for the individuals ids).

        SNP_1 SNP_2 SNP_3 SNP_4 SNP_5
2014TOR010  1   3 1 4 4 3 3 2 3 1
2014TOR010  1   1 1 2 4 3 3 2 4 1 
06SELI0115  1   3 1 4 4 3 3 2 3 1  
06SELI0115  1   3 1 2 4 3 2 2 3 2
2014TOR011  1   3 1 4 4 3 3 2 3 1 
2014TOR011  1   1 1 2 4 1 3 2 4 2 
....

I want to sort this file based on another another file:

head sorted.snps.txt
2014TOR011
06SELI0115
2014TOR010

but I want to keep the header.This is my desired out put: head out.desired

      SNP_1 SNP_2 SNP_3 SNP_4 SNP_5
2014TOR011  1   3 1 4 4 3 3 2 3 1 
2014TOR011  1   1 1 2 4 1 3 2 4 2
06SELI0115  1   3 1 4 4 3 3 2 3 1  
06SELI0115  1   3 1 2 4 3 2 2 3 2
2014TOR010  1   3 1 4 4 3 3 2 3 1
2014TOR010  1   1 1 2 4 3 3 2 4 1 
....

1 Answer 1

3

Untested:

awk '
NR==1 { print; next }
NR==FNR { a[$1]=($1 in a ? a[$1] ORS : "") $0; next }
{ print a[$1] }
' file1 sorted.snps.txt
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .