This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove columns from the VCF file using vcftools

I have a vcf file and I would like to remove four columns (CHROM,POS,ID,REF). I used the following command to extract these columns of my vcf file, but it's not working.

vcf-subset -c CHROM,POS,ID,REF my.vcf > out.vcf

What else should I add to that command?

vcftools

if you want to remove headers and first 4 columns:

 $ awk -v OFS="\t" '!/##/ {$1=$2=$3=$4="";print}' test.vcf|sed 's/^\s\+//g'

If you want to retain headers, but remove first 4 columns:

$ awk -v OFS="\t" '!/##/ {$1=$2=$3=$4=""}1' test.vcf |sed 's/^\s\+//g'

with sed:

$ sed -e '/##/! s/^\([^\t]*\t\)\{4\}//g' test.vcf | grep -v "##"

1 answer

cut  --complement -f 1-4 my.vcf | grep -v "^##"> out.vcf

shouldn't it be (as OP wants to remove the columns, not retain)?

cut --complement -f1-4  my.vcf | grep -v "^##"> out.vcf

Log in to answer this question.