Šaman Bobo
Šaman Bobo

Reputation: 75

Using sed to replace some lower case letters to upper case

I'm trying to replace _[lowercase] to [uppercase] using sed in bash.

So far I've tried this code:

new_arr=$( echo $old_arr | sed -e 's%_\(.\)%\1\U%g' )

With input of

this_is_a_function()

i expected the output to be

thisIsAFunction()

but i got

thisisafunction

Do you have a suggestion for what I might be doing wrong?

Upvotes: 1

Views: 725

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133428

Could you please try following.

sed 's/_\([a-z]\)/\U\1/g'  Input_file


So in OP's case it should be something like:

new_arr=$( echo "$old_arr" | sed 's%_\([a-z]\)%\U\1%g' )

Upvotes: 3

Related Questions