I'm trying to convert character strings like 123456a to 123456A or test to Test, but leave existing uppercase as is, for example testHW becomes TestHW.I have tried many attempts circling around:sed 's/[[:alpha:]]./\u\1/'without luck - any ideas?
Using sed to uppercase the first non-numeric character, leave others as is
sed
\1 or general form \n where n is a digit shall be replaced by the text matched by corresponding back-reference expression, which you define by grouping the text between \(...\) with BRE or (...) with ERE.With GNU sed:$ echo 123456a | sed 's/\([[:alpha:]]\)/\u\1/'123456Aor:$ echo 123456a | sed -E 's/([[:alpha:]])/\u\1/'123456AYou can also use & to refer to the text matched instead of back-reference:$ echo 123456a | sed 's/[[:alpha:]]/\u&/'   123456ANote that [:alpha:] matches both lowercase and uppercase characters, so something like 123456Aa will be left as-is.If you want to replace the first lowercase with corresponding uppercase, you must use [:lower:]:$ echo 123456Aa | sed 's/[[:lower:]]/\u&/'123456AA