我想讀取當前目錄中的所有檔案,并希望將結果保存在另一個目錄中。代碼如下,但無法獲取例外目錄中的檔案。有沒有人可以幫助我。
for file in *.sorted.bam
do
samtools index "$file" -o "${file%.sort.bam}".bam | mv /mnt/d/Document/bt2Alignment_result
done
謝謝!
uj5u.com熱心網友回復:
這是您的代碼的固定版本:
for file in *.sorted.bam
do
outfile="${file%.sorted.bam}.bam"
samtools index "$filepath" -o "$outfile"
mv "$outfile" /mnt/d/Document/bt2Alignment_result/
done
備注:*.sorted.bam您在嘗試剝離后綴時使用了 glob.sort.bam
也就是說,我認為您甚至不需要mv輸出檔案,因為samtools可以直接在您想要的位置創建它(使用-o選項)。另一方面,有時在 glob 中指定路徑很方便,例如./datadir/*.sorted.bam,因此您應該這樣做:
for filepath in ./*.sorted.bam
do
filename=${filepath##*/}
outpath=/mnt/d/Document/bt2Alignment_result/"${filename%.sorted.bam}.bam"
samtools index "$filepath" -o "$outpath"
done
uj5u.com熱心網友回復:
在下一行使用 mv 和 *.sorted.bam
for file in *.sorted.bam
do
samtools index "$file" -o "${file%.sorted.bam}".bam
mv *.sorted.bam /mnt/d/Document/bt2Alignment_result/
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/449201.html
