I'm trying to capitalize the first letter of every word in a string using the following sed command, but it's not working:
echo "my string" | sed 's/\b\(.\)/\u\1/g'
Output:
my string
What am I doing wrong?
Thank you
Given your sample input, this will work in any awk:
$ echo 'my string' | awk '{for (i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2)} 1'
My String
If that doesn't do what you really want then edit your question to show some more truly representative sample input and expected output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With