wyntia
wyntia

Reputation: 25

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:

etc.

Upvotes: 1

Views: 271

Answers (1)

sseLtaH
sseLtaH

Reputation: 11207

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/)

Upvotes: 1

Related Questions