Capitalize words in a string with sed | |
Thursday Jan 5 1:15:50 2023 | |
------------------------------ | |
I've got a small collection of .avi files and I wanted to capitaliz | |
each word in their names because I find it easier to read | |
"This.Is.An.Avi.File.avi" than "this.is.an.avi.file.avi". Renaming | |
them all by hand is a daunting thing to do. I am sure that there | |
might be some graphical software to do it out there, but I am not | |
keen on desktop applications of any kind (with some exceptions). | |
I found this sed line on the internet that works like a charm: | |
sed -e "s/\b\(.\)/\u\1/g" | |
The only "problem" is that it also capitalizes the extension ".Avi" | |
Too bad! There is probably an easy way to tell sed not to do it, bu | |
I am not an expert in regexes, so I'd better not touch the line. | |
But then basename comes to the rescue since it can trim the extensi | |
of any file allowing you to substitute it for any other. Something | |
like this (silly as it may seem): | |
"$(basename $AVIFILE .Avi).avi" | |
This is of course in a script that makes renaming all my files a | |
blast! | |
UPDATE: I found a better way of renaming the extension as follows: | |
rename 's/\.Avi$/.avi/' |