Issue
I am trying to modify a string with the pattern 'VW_ABCD_EF_GHIJ_KLM_...' into 'AbcdEfGhjKlm...'
For example "s=VW_ABCD_EF_GHIJ_KLM" must become "AbcdEfGhjKlm".
So far I got s=VW_ABCD_EF_GHIJ_KLM; echo "${s,,}" | sed -e 's/vw\(.*\)/\1/g'
which produces "_abcd_ef_ghij_klm".
I think I would have to create a variant number of groups for \(_.*\)
and replace '_[a-z]' for '[A-Z]' in every group, but I could not find how to do it
Solution
Expanding on OP's current code to strip the _
and U
ppercase the letter following the _
:
$ s='VW_ABCD_EF_GHIJ_KLM'
$ sed -e 's/vw\(.*\)/\1/g;s/_\(.\)/\U\1/g' <<< "${s,,}"
AbcdEfGhijKlm
One equivalent while limiting the VW
removal to the start of the string:
$ s='VW_ABCD_EF_GHIJ_KLM'
$ sed -E 's/^vw//g;s/_(.)/\U\1/g' <<< "${s,,}"
AbcdEfGhijKlm
NOTE: assumes each _
is followed by a letter (as in OP's example)
Answered By - markp-fuso Answer Checked By - Robin (WPSolving Admin)