I need to uncompress a .gz file and store it in a variable, so I can use it later. So, the idea is that I generate *.fastq.gz files, and I need to uncompress them and keep just the *.fastq file. Then, I would like to store its name in a variable, so I can call the file for further processing.
Here, there is the code I am executing: input: $file.fastq.gz Where $file is the name of the file (it changes, as this code is inside a loop)
reads=$(gunzip $file.fastq)
echo $reads
Does anybody know what is wrong with this code? Why it does not produce any output and the program stays in that point? Thank you very much! ;)
1) reads=$(gunzip $file.fastq) <--- first you should be doing your gunzip on the .gz file
2) echo $reads - You cannot store the uncompressed file in the variable .. so you cannot expect that the variable reads would have the name of the uncompressed file.
You should rather be using
Or a shorter syntax as suggested by Charles
If the input file is
$file.fastq.gz
, the resulting output file is just that file with the.gz
extension removed.(Original answer to misinterpreted question, saved as a useful non-sequitor.)
You need to tell
gunzip
to write the uncompressed stream to standard output, rather than uncompressing the file in-place.Use zcat: