bash 脚本新手,我制作了脚本来自动运行程序在 100 个不同的文件上运行,有人可以更正该脚本吗?在一个目录中,我有 1 到 100 个文件,其后缀为 *_R1_sic.fast 和 *_R2_sic.fast 对于所有文件都是通用的。
#!/bin/bash
set -e
for i in *_R*_sic.fast
do
SAMPLE=$(echo ${i} | sed "s/_R1_\sic.fast//" | sed "s/_R2_\sic.fast//")
echo ${SAMPLE}_R1_sic.fast
echo ${SAMPLE}_R2_sic.fast
time /home/cent/anaconda3/envs/cot_env/bin/cot_cpp cot -k 25 -l 100 -p /home/cent/data/dy_samples/gz/trim/bssp/dat_files/${SAMPLE}_R1_sic.fast /home/cent/data/dy_samples/gz/trim/bssp/dat_files/${SAMPLE}_R2_sic.fast -o /home/cent/data/dy_samples/gz/trim/bssp/dat_files/${SAMPLE}_R_001_trimo25p_shat -t 5 -u 5 -g 150 -m 150G > ${SAMPLE}_R_001_trimo25p_shat_log
done
答案1
你可能想要这个:
dat_files=/home/cent/data/dy_samples/gz/trim/bssp/dat_files
cot_bin=/home/cent/anaconda3/envs/cot_env/bin
for r1 in *_R1_sic.fast; do
sample=${r1%_R1_sic.fast} # trim the _R1... suffix
r2=${sample}_R2_sic.fast # add the _R2 suffix
if [[ -f $r2 ]]; then
out=${sample}_R_001_trimo25p_shat
cot_args=(
-k 25
-l 100
-p "$dat_files/$r1" "$dat_files/$r2"
-o "$dat_files/$out"
-t 5
-u 5
-g 150
-m 150G
)
time "$cot_bin/cot_cpp" cot "${cot_args[@]}" > "${out}_log"
fi
done