我需要解压缩 .gz 文件并将其存储在变量中,以便稍后使用。因此,我的想法是生成 *.fastq.gz 文件,并且需要解压缩它们并仅保留 *.fastq 文件。然后,我想将其名称存储在一个变量中,以便我可以调用该文件进行进一步处理。
这里是我正在执行的代码: 输入:$file.fastq.gz 其中 $file 是文件名(它会更改,因为此代码位于循环内)
reads=$(gunzip $file.fastq)
echo $reads
有人知道这段代码有什么问题吗?为什么它不产生任何输出并且程序停留在该点?非常感谢! ;)
最佳答案
如果输入文件是 $file.fastq.gz
,则生成的输出文件就是删除了 .gz
扩展名的文件。
gunzip "$file.fastq.gz" & gunzip_pid=$!
reads="$file.fastq"
# Do some more work that doesn't depend on the contents of $file.fastq
# ...
wait $gunzip_pid || { echo "Problem with gunzip"; exit; }
# Do something with the now-complete $file.fastq here
(对被误解的问题的原始答案,保存为有用的非推论。)
您需要告诉gunzip
将未压缩的流写入标准输出,而不是就地解压缩文件。
reads=$(gunzip -c "$file.fastq.gz") || { echo "Problem with gunzip; exit; }
echo "$reads"
关于linux - bash 解压缩 gz 并存储在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22177113/