Capitalize the First Letter of Every Word - Sh Script


Linux

Linux has powerful text conversion programs built in. Proper name and article title are a few examples of words that should have the first letter capitalized. If this needs to be done with large volumes of text, a shell script can save time.

phrase=”text to be converted here“;

capitals=$(for i in $phrase; do convert=`echo -n “${i:0:1}” | tr “[:lower:]” “[:upper:]“`; echo -n “${convert}${i:1} “; done | sed ’s/^[ \t]*//;s/[ \t]*$//’)

echo $capitals;

output=”Text To Be Converted Here”

Leave a Reply