Issue
I could not get the regex to convert only the key from a key value pair from camel case to underscore sting.
The expressions like sed -E 's/\B[A-Z]/_\U&/g' converts the full value, but I would like to limit the conversion only to the key here.
$ echo UserPoolId="eu-west-1_6K6Q2bT9c" | sed -E 's/\B[A-Z]/_\U&/g'
User_Pool_Id=eu-west-1_6_K6_Q2b_T9c
but i would like to get User_Pool_Id=eu-west-1_6K6Q2bT9c
Solution
If you have only one =
sign and you want to modify the camel case before the =
sign, with GNU sed
you can iterate until all substitutions are done:
echo UserPoolId="eu-west-1_6K6Q2bT9c" | sed -E ':a;s/([a-z])([A-Z].*=.*)/\1_\2/;ta'
User_Pool_Id=eu-west-1_6K6Q2bT9c
:a
sets label a
, ta
branches to label a
if the previous s
command substituted something. The s
command in the loop inserts a _
between a lower case and an upper case before the equal sign.
In your example this will first insert a _
between User
and Pool
, and then between Pool
and Id
.
Answered By - Renaud Pacalet Answer Checked By - Mary Flores (WPSolving Volunteer)