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

changing file extensions using sed command in linux

I wanted to change all of the files extensions in a folder to .jpg using only sed command.

I tried using

sed -i 's/\.*/\.jpg/g' ~/cw/ 

cw is my folder where i have files like:

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

  • cat.jpg

  • dog.JPG

  • frog.jpeg

etc.

>Solution :

Using sed

sed -n 's/\(^[^.]*\.\)[jJ][pP]e\?[gG]/mv & \1jpg/p' <(find ~/cw/)

If the dry run indeed changes the files to the expected extension, then you can then execute the command within the sed command

sed -n 's/\(^[^.]*\.\)[jJ][pP]e\?[gG]/mv & \1jpg/pe' <(find ~/cw/)
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