This is a test version of Biostars. For the public version, visit https://www.biostars.org.
variant analysis and filtering from annotation file

I have a annotation.txt file like this : chr1 34567 A chr2 12345 C chr14 14567 T chr15 32456 A

I want to extract data of chr1 only. I'm using following command: awk '$1 ~/chr1/' annotation.txt > chr1.txt

But it is giving me results for chr11, chr12 , chr13, chr14, chr15, chr16, chr17, chr18, chr19 as well. please help me to extract data of just chr1.

r snp

1 answer

Depends on the exact format of the file - if there are multiple lines where chr1 may occur:

awk 'match($0,/chr1 [0-9]+ [ACTG]/) {print substr($0,RSTART,RLENGTH)}' annotation.txt > chr1.txt

Log in to answer this question.