Reputation: 850
I have some files I need to rename in bulk. For example:
Jul-0961_S7_R2_001.fastq.gz
Jul-0967_S22_rep1_R1.fastq.gz
Jul-0974_S32_R2_001.fastq.gz
I need to remove the S* part of the filename but I don't know the right regular regex to use.
Specifically:
Jul-0961_S7_R2_001.fastq.gz --> Jul-0961_R2_001.fastq.gz
Something like, rename 's/S*//' *.gz is what I'm looking for.
Is there a regex wizard out there who can show me the way? Thanks in advance.
Upvotes: 0
Views: 49
Reputation: 12867
If the files are in the same format (i.e have the same number of underscores, you could use:
"ls" | awk -F_ '{ system("mv "$0" "$1"_"$3"_"$4) }'
Here we are using underscore as the delimiter and then building a command to execute with the system function
Upvotes: 2