Uppercasing First Letter of Words Using SED


Question

How do you replace the first letter of a word into Capital letter, e.g.

Trouble me
Gold rush brides

into

Trouble Me
Gold Rush Brides
1
37
10/8/2009 3:50:33 PM

Accepted Answer

This line should do it:

sed -e "s/\b\(.\)/\u\1/g"
65
10/8/2009 4:09:44 PM

Using awk:

awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1' file

The output would be:

Trouble Me
Gold Rush Brides

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon