Hi everyone,
I have little experience in bash and would like to rename multiple fastq.gz files. I know this question has already been asked multiple times, but nothing I have tried has worked so far, unfortunately.
Original names are as follows:
JM1-44589688_S693_L001_R1_001.fastq.gz
JM110-44589731_S719_L001_R2_001.fastq.gz
I would the final names like this:
JM1_1.fastq.gz
JM110_2.fastq.gz
I tried to use the rename command but I didn't manage to find a way to delete only de central part of the label using this command.
I also tried this:
rename '-' '_' *fastq.gz
for i in *.fastq
do
mv $i $(echo $i | awk '{split($1,a,/_/); print a[1]"_"a[5]}')
done
But this way I lose the suffix .fastq.gz
.
Your help will be very much appreciated!
Here's another safe solution using brename (download). Personally, I usually avoid batch renaming files with
mv
, which might overwrite existing files by accident.