This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Concatenate All Vcf.Gz Files

hi all. i am a bit new to linux environment and i wanted to how the following command could be modified to concatenate all VCF files from a directory.

vcf-concat A.vcf.gz B.vcf.gz C.vcf.gz | gzip -c > out.vcf.gz

instead of A.vcf.gz, B.vcf.gz I would like all vcf.gz from my directory concatenated knowing they are all from the same source.

thanks in advance.

vcf

2 answers

Well, the command you gave is 90% of the answer you're looking for. To match several files, you can use shell wildcards (also called globs) like * which the shell expands to match many files. For example to convert all files ending in vcf.gz in a directory called myvcfs you can just use:

vcf-concat myvcfs/*.vcf.gz | gzip > out.vcf.gz

The -c for gzip in your original command is not strictly necessary because it's the default anyway. If you're paranoid you might want to add -s to vcf-concat which does some checks for you (assumes that your files are tabix indexed).

Andreas

vcf-concat *.vcf.gz | gzip -c > out.vcf.gz

Simple as that. The bash expansion will convert that to a list of all vcfs

Log in to answer this question.