regex - Rename with pattern -


i have lot of files looking this:

"this file.txt" "this file.txt" "this m file.txt" "this m file.txt" 

so basically, if try describe it, filename composed of 2 parts, 1 in upper case, other in lower case (though first letter of second part can in upper case too). words can composed of 1 single char. when there's choice, single character word in upper case in considered of first part.

i'd extract first part of filename, composed of upper case words, put them lowercase (with first letter uppercase), , seperate rest hyphen.

so result i'm expecting is:

"this - file.txt" "this - file.txt" "this - m file.txt" "this m - file.txt" 

what have far is:

rename 's/^(([a-z]{2,}| )+)(.*)/\u\l$1\e - $3/g' * 

but there quite few problems (one letter upper case words don't match, , first word capitalized).

i think regex you're looking be:

s/^((?:[a-z]+ )+)/(join " ", map ucfirst, split " ", lc $1) . " - "/e 

i tested this:

$ perl -pe 's/^((?:[a-z]+ )+)/(join " ", map ucfirst, split " ", lc $1) . " - "/e' <<eoq file.txt file.txt m file.txt m file.txt eoq 

here's output:

this - file.txt - file.txt - m file.txt m - file.txt 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -