3

I don't want to unzip the vcf.gz file first because it's a big file and my laptop doesn't have space for it. I tried doing:

gunzip -c file.vcf.gz > bgzip -c > file.vcf.bgz

But it didn't work. Thoughts?

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
claudiadast
  • 419
  • 1
  • 9
  • 18
  • 3
    You should provide more details than just "it didn't work": Was there an error message? Is there some output? That said, I agree with @Pierre's answer. Here, you use a `>` on the output of gunzip, which redirects to a file (check that you haven't created a file called `bgzip`, by mistake). Instead, what you want is to redirect this to the "standard input" of the program `bgzip`, and the pipe (`|`) is the correct tool for this. – bli Oct 16 '17 at 09:43

1 Answers1

12

try

gunzip -c file.vcf.gz | bgzip  > file.vcf.bgz
Pierre
  • 34,472
  • 31
  • 113
  • 192
  • upvoted for this answer...how can the same command be used for multiple files? If its rename, it can work. But how can I do `gzip` operation on multiple files and have their file extension changed to .bgz? – The Great Sep 10 '20 at 15:50
  • @TheGreat you need to use a loop, e.g. `for f in file*vcf.gz; do gunzip -c $f | bgzip > $(basename -s .gz $f).bgz; done`. This will take each file and rezip it with bgzip. Note that `basename` will remove any directory from the filename, so the final files will be in your current directory - you could prepend the destination like this: `... > some_path/$(basename ...).bgz` to put the files in specific directory. – jena Aug 03 '21 at 10:30