Batch replace substring with another in filenames

I have a bunch of files named similar to this:

1_1.pngEND1_1.png

How would you replace .pngEND with _?

I've googled this problem and tried literally 5+ solutions, non of which worked on mac.


Solution 1:

There are tons of ways to do this, for instance

for i in *pngEND*.png; do [[ -e ${i/.pngEND/_} ]] || echo mv "$i" "${i/.pngEND/_}"; done

Remove the echo if the output looks sensible.

Solution 2:

Unless you need a solution you can use in a script, you can do this directly in Finder.

  • Select the files you want to rename
  • Right click one of them, and choose Rename N Items... (where N is the number of selected files)
  • Choose the Replace Text option in the dropdown
  • Enter the text you want to replace (".pngEND") and the text you want to replace it with ("_")
  • Click Rename