Use sed or rename find series of alphabet then replace with with the same alphabet and a dash -

54 views Asked by At

I have some images and folders to rename. They are contained in the folder with the same filename as such.

/abc123
/abc123/abc123.jpg

None of the filenames or folder names have a dash which I want to add after the alphabet. And some of the filenames are already capitalised, but none of the folder names are capitalised. So I want to achieve the following:

From current image name and folder name:

abc123.jpg
ABC123.jpg
/abc123
wxyz123456.jpg
/wxyz123456

to the desired:

ABC-123.jpg
/ABC-123
WXYZ-123456.jpg
/WXYZ-123456

I used rename 's/\(^[a-zA-Z]*\)/$1-/' *.jpg to rename the images and rename 's/\(^[a-zA-Z]*\)/$1-/' * for the folders.

This code is recognising the alphabets in front of the numbers, but I do not know how to output that same pattern space and add a dash after it. I thought either \1 or $1 would work, but it didn't.

What am I missing?

0

There are 0 answers