Krishna Kuntala Krishna Kuntala - 1 month ago 10
Bash Question

Convert a capital case string to camel case using shell script

I am trying to convert a Capital case word to camel case using shell script. e.g.

ProjectAssignment
should be converted to
projectAssignment
.

echo "project assignment" | sed 's/.*/\L&/; s/[a-z]*/\u&/g'


This produces output as :
Project Assignment


On the similar lines, I want to convert
ProjectAssignment
to
projectAssignment
.

Answer

You can do this with gnu-sed:

s='ProjectAssignment'
echo "$s" | sed 's/^[A-Z]/\L&/'

projectAssignment

^[A-Z] will match only the first letter if it is uppercase.