I am working via ssh on a remote cluster and need to rename some files according to a scheme. The rename should work like:
M-19-3778_P1-DX5-K47-232-Elev_A1-A1_L001_R1_001.fastq.gz
into M-19-3778-P1-DX5-K47-232-Elev-A1-A1L001_R1.R.fq.gz
M-19-3778_P1-DX5-K47-232-Elev_A1-A1_L001_R2_001.fastq.gz
into M-19-3778-P1-DX5-K47-232-Elev-A1-A1L001_R1.F.fq.gz
M-19-3779_P1-F48-F37-86-Cont_A2-A2_L001_R1_001.fastq.gz
into M-19-3779-P1-F48-F37-86-Cont-A2-A2L001_R2.R.fq.gz
M-19-3779_P1-F48-F37-86-Cont_A2-A2_L001_R2_001.fastq.gz
into M-19-3779-P1-F48-F37-86-Cont-A2-A2L001_R2.F.fq.gz
...
M-19-3830_P1-DX5-D12-221-Elev_F9-F9_L001_R1_001.fastq.gz
into M-19-3830-P1-DX5-D12-221-Elev-F9-F9L001_R53.R.fq.gz
M-19-3830_P1-DX5-D12-221-Elev_F9-F9_L001_R2_001.fastq.gz
into M-19-3830-P1-DX5-D12-221-Elev-F9-F9L001_R53.F.fq.gz
Iterations are only in the beginning of the names with 3778....
So far I've tried it with combinations of grep
/ sed
/ cat
but did not succeed. And I have no idea how to handle the iteration in the end of the name R1
, R2
,..., my guess would be a combination of a for
loop and an if
-Statement but I just don't get this running.
I would be grateful for any help!
i=1
for name in *
do
newName=${name%_L001_R1_001.fastq.gz}L001_R$i.R.fq.gz
mv "$name" "$oldname"
((i++))
done
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.