1

I'm fairly inexperienced with *nix scripting, and I have a need to take a string with lowercase words separated by dashes and convert that to a new string with the dashes removed, and the first letter after each original dash uppercased. For example, I want to take

one-two-three-four-five

and convert it to

oneTwoThreeFourFive

The solution must be able to handle multiple dashes (including none), and can use other *nix utilities if necessary like sed, awk, etc.

4
  • What do you mean be "including none" - that would just be the original word... onetwo-three would be onetwoThree
    – Kinnectus
    Jun 22, 2016 at 11:23
  • @BigChris I think OP simply means that the proposed solution cannot assume that any dashes are present at all, and must gracefully handle that case.
    – user
    Jun 22, 2016 at 11:28
  • @MichaelKjörling And split the words for him? Gee, I'll pass on this one. Jun 22, 2016 at 13:11
  • @MichaelKjörling - That's correct. If I were to pass in the string 'baseball' the solution must return that untouched ... Jun 22, 2016 at 16:10

1 Answer 1

2

Perl to the rescue:

echo one-two-three-four-five | perl -pe 's/-(.)/\u$1/g'

\u upcases the following character.

2
  • Works perfectly. Tested on MacOS (El Capitan). Jun 22, 2016 at 16:11
  • Also tested on Debian Wheezy and works like a charm.
    – user
    Jun 22, 2016 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .