Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to rename files: picture.jpg.~1~ to picture_~1~.jpg

I have say 30000 files of this type: picture.jpg.~12~

They are remnants of a backup (mv -v –backup=numbered …).

I needed to switch the extensions to: picture.~12~.jpg

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I have found this solution finally which might inspire you in This Long Dark Covid-time of the Soul.

ls *~*~* | sed -n "s/\(.*\)\.\([^.]*\).\(~[0-9]*~\)$/mv  -v --backup=numbered  \"\0\" \"\1_\3.\2\"/p" >switch_extensions.sh
chmod +x switch_extensions.sh
./switch_extensions.sh > switch_extensions.log

The first line produces commands:

mv  -v --backup=numbered  "Trombone.tif.~10~" "Trombone_~10~.tif"

The second line makes it executable, the third is renaming while creating a log file. Then swiftly comes relief from the dark soul ruminations. Try it!

You might know a smarter solution, so let brains storm!
🙂

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading