7

My files are of the format

Country, City S1.txt

e.g.

USA, Los Angeles S1.txt
USA, San Francisco S3.txt
UK, Glouchester S4.txt
Argentina, Buenos Aires S7.txt

I wish to change them to

Country_City_S1.txt

e.g.

USA_Los_Angeles_S1.txt
USA_San_Franciso_S3.txt
UK_Glouchester_S4.txt
Argentina_Buenos_Aires_S7.txt

Can someone help me please, preferably using the mv command? Thanks.

Raffa
  • 32,237
alien.on.earth
  • 151
  • 2
  • 7
  • 1
    There is 1 thing missing from the question: How do you want duplicates handeled? – Rinzwind Jul 07 '22 at 16:24
  • @Rinzwind Since there are no duplicates now, in what circumstances might one expect duplicates in the process of renaming? – MDeBusk Jul 07 '22 at 18:10
  • already existing Country_City_S1.txt or 2 files with names Country, City S1.txt + Country City S1.txt. Mind there is another issue: he said commas AND spaces. So Country, City S1.txt should technically be replaced to Country__City_S1.txt (3x _) and either the title is wrong or the body ;-) Seems nitpicking but ... mv is not so forgiving when it comes to duplicates so better safe than sorry :D
  • – Rinzwind Jul 07 '22 at 18:46
  • 1
    Agree with sentiment of Rinzwind here. It's always important to at least acknowledge the possibility of duplicate/filename clash when renaming, and confirm that it is not an issue in our data before moving on, since as Rinzwind said, mv is not very forgiving on that. – justhalf Jul 08 '22 at 08:27