views:

100

answers:

4

I try to capitalize the first letter in a CSV which is sorted like this:

a23;asd23;sdg3

What i want is a output like this

a23;Asd23;Sdg3

So the first String should be as is, but the second and third should have a capitalized first letter. I tried with AWK and SED but i didn't find the right solution. Can someone help?

+1  A: 
echo "a23;asd23;sdg3" | perl -ne 's/(?<=\W)(\w)/ uc($1) /gex;print $_'

a23;Asd23;Sdg3
eumiro
+6  A: 

Just capitilise all letters that follow a semicolon:

sed -e 's/;./\U&\E/g'
Bart Sas
Thank you. That was exactly what i've searched. :-)
fwa
+1  A: 

Bash has a "first uppercase" operator, ${var^}, but in this case I think it is better to use sed:

sed -r 's/(^|;)(.)/\1\U\2/g' <<< "a23;asd23;sdg3"

enzotib
+1  A: 
$ var="a23;asd23;sdg3"
$ echo $var | awk -F";" '{for(i=2;i<=NF;i++) $i=toupper(substr($i,i,1))substr($i,1) }1' OFS=";"
a23;Sasd23;Gsdg3
ghostdog74