I am trying to make a sed script that will make the first letter of each
molly w. bolt 334-78-5443
walter q. bugg 984-49-0032
noah p. way 887-12-0921
So I want it to look like this:
Molly W. Bolt 334-78-5443
Walter Q. Bugg 984-49-0032
Noah P. Way 887-12-0921
So far I have the following script, but it will only capitalize the first two words it comes across ie. making it Molly W. bolt. I can't figure out how to modify the script to get the last name uppercase. What do I need to add?
h
s/\(.\).*/\1/
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
G
s/\(.\)\n\(.\)\(.*\)/\1\3/
/ [a-z]/{
h
s/\([A-Z][a-z]* \)\([a-z]\).*/\2/
y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
G
s/\(.\)\n\([A-Z][a-z]* \)\(.\)\(.*\)/\2\1\4/
}
this gnu sed one liner may help you:
sed 's/\b./\u&/g' file
test with your data:
kent$ cat f
molly w. bolt 334-78-5443
walter q. bugg 984-49-0032
noah p. way 887-12-0921
kent$ sed 's/\b./\u&/g' f
Molly W. Bolt 334-78-5443
Walter Q. Bugg 984-49-0032
Noah P. Way 887-12-0921
Use the word boundary \b
and \U
to uppercase:
sed 's/\b./\U&/g'
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