TG Telegram Group & Channel
GeekTips | United States America (US)
Create: Update:

either brew install titlecase (perl) is the one I currently use. pip3 install titlecase (python) one is just as good.

This (awk) one though is pretty good I refined somewhat. If it's all caps it'll titlecase it but if just some are caps it'll assume they're acronyms and leave them untouched.

005 Of Mice And Men Of The Best
becomes 005 Of Mice and Men of the Best
Notice the Of after the number stays caps but the other of doesn't.

If not numbers for chapters that'll also work.
Lord Of The Rings
Lord of the Rings

brew install gsed 

for Mac and just change gsed to sed on Linux

title="005 Of Mice And Men Of The Best"; newtitle=$(echo "$title" | sed -E -e 's/^([0-9]+)//g' -e 's/:/:/g' -e 's/\|/-/g' -e 's/\//-/g'); num=$(echo "$title" | sed -E 's/(^[0-9]+ )*(.*)/\1/g'); echo -n "$num"; echo -n "$newtitle" | awk 'BEGIN{split("a the to at in of on with and but or",w); for(i in w)nocap[w[i]]}function cap(word){return toupper(substr(word,1,1)) tolower(substr(word,2))}{for(i=1;i<=NF;++i){printf "%s%s",(i==1||i==NF||!(tolower($i) in nocap)?cap($i):tolower($i)),(i==NF?"\n":" ")}}' | gsed -E -e 's/(\s*-\s*)([a-z])/\1\u\2/g' -e 's/(\s*:\s*)([a-z])/\1\u\2/g' -e 's/(^[0-9]+) ([a-z])/\1 \u\2/g'

either brew install titlecase (perl) is the one I currently use. pip3 install titlecase (python) one is just as good.

This (awk) one though is pretty good I refined somewhat. If it's all caps it'll titlecase it but if just some are caps it'll assume they're acronyms and leave them untouched.

005 Of Mice And Men Of The Best
becomes 005 Of Mice and Men of the Best
Notice the Of after the number stays caps but the other of doesn't.

If not numbers for chapters that'll also work.
Lord Of The Rings
Lord of the Rings

brew install gsed 

for Mac and just change gsed to sed on Linux

title="005 Of Mice And Men Of The Best"; newtitle=$(echo "$title" | sed -E -e 's/^([0-9]+)//g' -e 's/:/:/g' -e 's/\|/-/g' -e 's/\//-/g'); num=$(echo "$title" | sed -E 's/(^[0-9]+ )*(.*)/\1/g'); echo -n "$num"; echo -n "$newtitle" | awk 'BEGIN{split("a the to at in of on with and but or",w); for(i in w)nocap[w[i]]}function cap(word){return toupper(substr(word,1,1)) tolower(substr(word,2))}{for(i=1;i<=NF;++i){printf "%s%s",(i==1||i==NF||!(tolower($i) in nocap)?cap($i):tolower($i)),(i==NF?"\n":" ")}}' | gsed -E -e 's/(\s*-\s*)([a-z])/\1\u\2/g' -e 's/(\s*:\s*)([a-z])/\1\u\2/g' -e 's/(^[0-9]+) ([a-z])/\1 \u\2/g'


>>Click here to continue<<

GeekTips




Share with your best friend
VIEW MORE

United States America Popular Telegram Group (US)