Spinal Case to Camel Case

GNU sed

This works with GNU sed:

sed -r 's/(^|-)(\w)/\U\2/g'

Match the start of the line or a - followed by an alphanumeric character and use \U to make the character uppercase.

And here's how you can operate on a variable with it and assign the result to another variable:

name_upper=$(sed -r 's/(^|-)(\w)/\U\2/g' <<<"$name_spinal")

Perl

It's almost identical in perl:

perl -pe 's/(^|-)(\w)/\U$2/g'

Native bash

Just for fun, here's a way you could do it in native bash:

spinal_to_upper() {
    IFS=- read -ra str <<<"$1"
    printf '%s' "${str[@]^}"
}

spinal_to_upper "some-string-like-this"

Tags:

Bash

Sed