Reputation: 1119
SET_VALUE(ab.ms.r.gms_dil_cfg.f().gms_dil_mode, dsad_sd );
How can I use sed
to replace only from the SET_VALUE
until the , with each letter after _
to be upper case?
result:
SET_VALUE(ab.ms.r.gmsDilCfg.f().gmsDilMode, dsad_sd );
Upvotes: 1
Views: 163
Reputation: 92854
For your input string you may apply the following sed expression + bash variable substitution:
s="SET_VALUE(ab.ms.r.gms_dil_cfg.f().gms_dil_mode, dsad sd )"
res=$(sed '1s/_\([a-z]\)/\U\1/g;' <<< "${s%,*}"),${s#*,}
echo "$res"
The output:
SET_VALUE(ab.ms.r.gmsDilCfg.f().gmsDilMode, dsad_sd );
Upvotes: 2
Reputation: 34334
Got distracted while writing this one up so Roman beat me to the punch, but this has a slight variation so figured I'd post it as another option ...
$ s="SET_VALUE(ab.ms.r.gms_dil_cfg.f().gms_dil_mode, dsad_sd );"
$ sed 's/,/,\n/g' <<< "$s" | sed -n '1{s/_\([a-z]\)/\U\1/g;N;s/\n//;p}'
SET_VALUE(ab.ms.r.gmsDilCfg.f().gmsDilMode, dsad_sd );
s/,/,\n/g
: break input into separate lines at the comma (leave comma on first line, push rest of input to a second line)sed
invocation will now be working with a 2-line inputsed -n
: refrain from printing input lines as they're processed; we'll explicitly p
rint lines when required1{...}
: for the first line, apply the commands inside the braces ...s/_\([a-z]\)/\U\1/g
: for each pattern we find like '_[a-z]', save the [a-z]
in buffer #1, and replace the pattern with the upper case of the contents of buffer #1N
: read and append the next line into the pattern spaces/\n//
: replace the carriage return with a null characterp
: print the pattern spaceUpvotes: 0