gpt4 book ai didi

linux - bash 解压缩 gz 并存储在变量中

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:38:12 28 4
gpt4 key购买 nike

我需要解压缩一个 .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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com