Search code examples
bashshellcamelcasing

How can I cut(1) camelcase words?


Is there an easy way in Bash to split a camelcased word into its constituent words?

For example, I want to split aCertainCamelCasedWord into 'a Certain Camel Cased Word' and be able to select those fields that interest me. This is trivially done with cut(1) when the word separator is the underscore, but how can I do this when the word is camelcased?


Solution

  • sed 's/\([A-Z]\)/ \1/g'

    Captures each capital letter and substitutes a leading space with the capture for the whole stream.

    $ echo "aCertainCamelCasedWord" | sed 's/\([A-Z]\)/ \1/g'
    a Certain Camel Cased Word