This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Change SNPID in vcf file with awk

Hi, I have a VCF file with SNP IDs like this:

AX-14233402__rs35404821
AX-37499887__rs74704183
AX-36783275__rs11997571

I would like to change the SNP IDs to have only the IDs without the AX-... term:

rs35404821 
rs74704183 
rs74704183

Is there any solution for this? I tried with a gsub command, but nothing changed:

awk '{gsub(/AX*_rs/,"rs"); print}' datafile.vcf > datafile_ID.vcf
vcf snpid

Do not delete posts when they've been addressed. If one or more solutions worked, accept them using the green check mark.

upvote_bookmark_accept

can you try one of these three?

$ awk -F "AX-.*__" '{print $1$2}' test.vcf 
$ awk -F "AX-.*__rs" -v OFS="rs" '{print $1,$2}' test.vcf 
$ sed '/\tAX.*__rs/ s//\trs/' test.vcf

1 answer

 awk -F '\t' '/^#/ {print;next;} {OFS="\t";gsub(/.*__rs/,"rs",$3);print}' < in.vcf 

Log in to answer this question.