Quick Command – replacing camelcase with underscore

Technical

sed 's/\([A-Z]\)/_\l\1/g' file.txt | sed 's/^_\([a-z]\)/\1/g'

Example:

user@M0096:~$ cat file.txt
oneTwoThreeFour
oneTwo
one
FourThreeTwo
user@M0096:~$ sed 's/\([A-Z]\)/_\l\1/g' file.txt | sed 's/^_\([a-z]\)/\1/g'
one_two_three_four
one_two
one
four_three_two

Advertisements

One thought on “Quick Command – replacing camelcase with underscore

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s