Algorithm: Find which file the SNP is in, then zgrep the SNP out.
This script will output a .dosage file for each snp in the list. to combine them into a file, it's of course just a matter of using "cat"
#Requires a list of SNPs written into snplist.txt dosage_directory=write_path_to_dosage_files_here for snp in $(cat snplist.txt) do filename=$(grep -w -m1 -l $snp "$dosage_directory"/*.map | sed 's/.map/.gz/g' ) zgrep -w -m1 $snp $filename > "$snp".dosage done #Note: if you want a header for these data, just take the top line from the dosage file, e.g. zcat dos_pts_psy4_mix_am-qc.hg19.ch.fl.chr1_027_030.out.dosage.gz | head -n1 > dosages.header