I have an excel file that I created from VCF file for common SNPs across 6 samples. This excel have the chromosomes and the position of the SNPs only (see example table1) enter image description here Now I would like to obtain the other information (eg. allels, Genotype, depth, etc) from the VCF files of the 6 samples (i.e. the one that contains these positions). I tried using AWK command like here for position 23432 on chr. 1 for the 6 file :

awk -F " " '$1=="1" && $2=="23432"' file1.vcf
awk -F " " '$1=="1" && $2=="23432"' file2.vcf
awk -F " " '$1=="1" && $2=="23432"' file3.vcf
awk -F " " '$1=="1" && $2=="23432"' file4.vcf
awk -F " " '$1=="1" && $2=="23432"' file5.vcf
awk -F " " '$1=="1" && $2=="23432"' file6.vcf

he issue is that these SNPs I have are thousands positions, so I need an automated way to do this

Could you advise on that ?


  • $\begingroup$ Is this related to your previous question? Is this the sites file that you opened using Excel? Please read the bcftools manual, they have everything you need. $\endgroup$
    – Ram RS
    Commented May 24, 2023 at 17:52
  • $\begingroup$ When working with VCF files, a tab-separated format, you want -F '\t'. And you never want -F " ", unless you truly want to break on spaces and only spaces. By default awk will split on any whitespace character (including tabs and spaces) so you don't need this. $\endgroup$
    – terdon
    Commented May 24, 2023 at 18:04
  • $\begingroup$ Don’t use awk or excel, please just use bcftools and save yourself a lot of trouble $\endgroup$
    – user438383
    Commented May 24, 2023 at 19:44
  • $\begingroup$ @user438383 OP has a separate thread going on with bcftools involved in solving this problem, looks like they chose to open a new thread for no apparent reason. $\endgroup$
    – Ram RS
    Commented May 24, 2023 at 21:03


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.