This script will output shell commands that perform a series of 'mv' commands to accomplish your task:
for FILE in *.fastq.gz
do
L="${FILE%%_*}_"
R="${FILE#${L}*_}";
printf 'mv -vi "%s" "%s"\n' "$FILE" "$L$R"
done
Run that once, and examine the output. If there are lots of files, you may want to use less
to review the commands.
If everything looks good, run the command again and pipe the output to bash
.
It works by setting the variable L to everything left of the first underscore in the filename, plus the underscore itself. It then forms a string R by stripping the string in L from the front of the filename, and stripping further to the next underscore.
mv -vi "Mabel-A10_GTAGAGGA_L001_R1_001.fastq.gz" "Mabel-A10_L001_R1_001.fastq.gz"
mv -vi "Mabel-A11_GCTCATGA_L001_R1_001.fastq.gz" "Mabel-A11_L001_R1_001.fastq.gz"
mv -vi "Mabel-A5_GGACTCCT_L001_R1_001.fastq.gz" "Mabel-A5_L001_R1_001.fastq.gz"
mv -vi "Mabel-A6_TAGGCATG_L001_R1_001.fastq.gz" "Mabel-A6_L001_R1_001.fastq.gz"