Uppercasing First Letter of Words Using SED

前端 未结 9 1383
误落风尘
误落风尘 2020-12-07 20:49

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

Trouble me
Gold rush brides

into

Trouble Me
Gold R         


        
9条回答
  •  孤城傲影
    2020-12-07 21:54

    I had apostrophes so, working off the first solution...

    mike@mike-laptop3:~$ echo "BEST WESTERN PLUS BOB's INN" | tr "[A-Z]" "[a-z]" | sed -e "s/\b\(.\)/\u\1/g"
    

    Best Western Plus Bob'S Inn

    mike@mike-laptop3:~$ echo "BEST WESTERN PLUS BOB's INN" | tr "[A-Z]" "[a-z]" | sed "s/\( \|^\)\(.\)/\1\u\2/g"
    

    Best Western Plus Bob's Inn

提交回复
热议问题