0

I have hundreds fast.gz files, and they have the same format of file name:

5809029_GWU_DNA_269_L001_R1_001.fastq.gz
5809030_GWU_DNA_269_L001_R1_001.fastq.gz

How do I change the first and the second underscores to dots? eg:

5809029.GWU.DNA_269_L001_R1_001.fastq.gz
5809030.GWU.DNA_269_L001_R1_001.fastq.gz

without changing the remaining underscores?

I have tried rename 's/_GWU_DNA/\.GWU\.DNA/' *gz, it didn't change anything. So I'm thinking about a for loop, any idea? Thank you!

Kusalananda
  • 333,661

1 Answers1

1

Here you have a mv possibility:

for f in *_GWU_*.gz; do 
  mv "$f" "${f/_GWU_/.GWU.}"
done
Kusalananda
  • 333,661