octosquidopus
octosquidopus

Reputation: 3713

sed: replace CamelCase by Camel:Case

I'm trying to insert a colon everywhere a lowercase letter is followed by an uppercase letter, and add characters around the first word: (from CamelCase to <Camel>:Case)

This is my best shot, based on: How to transfer characters between uppercase and lowercase with sed

echo CamelCase | sed -e 's/\([a-z][A-Z]\)/\1:/g'

CamelC:ase

What am I missing?

Upvotes: 2

Views: 1031

Answers (1)

anubhava
anubhava

Reputation: 784878

Try this sed:

echo 'CamelCase' | sed -e 's/\([a-z]\)\([A-Z]\)/\1:\2/g'
Camel:Case

UPDATE: As per comments:

echo 'CamelCase' | sed -e 's/\([A-Z][a-z]*\)\([A-Z]\)/<\1>:\2/g'
<Camel>:Case

Upvotes: 6

Related Questions