Sort vcf by contig and position within contig
You could simply use bcftools sort for it:

$ bcftools sort input.vcf &gt; output.vcf


If you really want to use bash only, you can do this:

$ grep "^#" input.vcf &gt; output.vcf
$ grep -v "^#" input.vcf| sort -k1,1V -k2,2g &gt;&gt; output.vcf


The first command will write the header information to the new vcf file.
The second will sort by contig name and position and append the result to the new vcf file.

fin swimmer