Rename with pattern
I have a lot of files looking like this:
"THIS IS my file.txt"
"THIS IS My file.txt"
"THIS IS m file.txt"
"THIS IS M file.txt"
So basically, if I try to describe it, it's a string composed of words
(eventually 1 character words) in upper case, then words in lower case
(eventually with first letter of word in upper case).
I'd like to extract the first part of the filename, composed of upper case
words, put them to lowercase (with just the first letter as uppercase),
and seperate it from the rest with an hyphen.
So the result I'm expecting is:
"This Is - my file.txt"
"This Is - My file.txt"
"This Is - m file.txt"
"This Is M - file.txt"
What I have so far is:
rename 's/^(([A-Z]{2,}| )+)(.*)/\u\L$1\E - $3/g' *
But there are quite a few problems with it (one letter upper case words
don't match, and only the first word is capitalized).
No comments:
Post a Comment