开发者

BASH - Make the first Letter Uppercase

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?


Just capitilise all letters that follow a semicolon:

sed -e 's/;./\U&\E/g'


Bash (version 4 and up) 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"


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

a23;Asd23;Sdg3


$ 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜