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!

  • Welcome! I'm trying your command with no issues, it renames the files. You don't need to escape the dots in the substitution. – guillermo chamorro Dec 3 '19 at 16:32
  • I'm using my terminal on MAC, it did nothing. – Freddie Dec 3 '19 at 16:38
  • do i need to install something? – Freddie Dec 3 '19 at 16:55
  • I'm not familiar with MAC, I don't know if rename is part of the system, or if it is, how it behaves, so I don't know if you have to install something, sorry. – guillermo chamorro Dec 3 '19 at 16:59
  • can i ask- where did you run the command? – Freddie Dec 3 '19 at 17:01
1

Here you have a mv possibility:

for f in *_GWU_*.gz; do 
  mv "$f" "${f/_GWU_/.GWU.}"
done
  • Thanks, this solved my question! – Freddie Dec 3 '19 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.