我在目录中有几个fastq.gz文件。我想删除每个文件名的部分内容。这是文件名
RES-1448-001_S289_L001_R1_001.fastq.gz
RES-1448-001_S289_L001_R2_001.fastq.gz
RES-1448-012_S300_L001_R1_001.fastq.gz
RES-1448-012_S300_L001_R2_001.fastq.gz
我想删除它后面的S和3位数以及L001。我希望在删除后能够这样做
RES-1448-001_R1_001.fastq.gz
RES-1448-001_R2_001.fastq.gz
RES-1448-012_R1_001.fastq.gz
RES-1448-012_R2_001.fastq.gz
非常感谢您的帮助
答案 0 :(得分:0)
bash
参数展开:
for file in *.fastq.gz; do
start=${file%%_*} ## Gets only the portion before first `_`
end=${file#*_*_*_*} ## Gets the portion after 3 `_`s from start
echo mv -- "$file" "${start}_${end}"
done
这只会echo
运行mv
命令,如果满意,请删除实际echo
操作的mv
:
for file in *.fastq.gz; do
start=${file%%_*}
end=${file#*_*_*_*}
mv -- "$file" "${start}_${end}"
done
答案 1 :(得分:-1)
使用perl
:
perl -ape 's{_S\d\d\d_L001}{}'