Set the 1st letter of each word to Uppercase

May 2017

You may be in a situation where you need to set letters in uppercase mode whilst typing: you could be writing a letter in Microsoft Word for example and require capital letters throughout your document. Similarly with programming the use of uppercase is often required. There are two methods by which uppercase can be set on the first letter of each word you type. It differs from person to person which one they decide to use, but the sed command along with echo is compulsory in both cases.
Below are two ways to proceed:

Method 1
sed-r 's /(^.|.) / \ U & / g'

Method 2
sed 's / ^. \ | [a-z] / \ U & / g'

Method 3
sed-r 's / \ <. / \ U & / g'

Examples:
$ Echo-e "good day to you | Sed-r 's /(^.|.) / \ U & / g'
Good Day To You.

$ Echo-e "hello life \ net hello to you" | sed-r 's /(^.|.) / \ U & / g'
or
$ Echo-e "hello life \ net hello to you" | sed-r 's / (\ b) / \ U & / g'
Hello Life
And Hello To You

$ Echo-e "hello life." | Sed 's / ^. \ | [A-z] / \ U & / g'
Hello Life.

$ Echo-e "hello life \ net hello to you" | sed 's / ^. \ | [Az] / \ U & / g'
Hi Life
And Hello To You

Related


Published by deri58. Latest update on March 14, 2012 at 04:54 PM by Virginia Parsons.
This document, titled "Set the 1st letter of each word to Uppercase," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).