Top
Convert camelCase to Underscores Using sed – Dragos Cirjan
fade
152
post-template-default,single,single-post,postid-152,single-format-standard,flow child-child-ver-1.0.0,flow-ver-1.3.6,,eltd-smooth-page-transitions,ajax,eltd-blog-installed,page-template-blog-standard,eltd-header-standard,eltd-fixed-on-scroll,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-dropdown-default

Warning: A non-numeric value encountered in /usr/src/wordpress/wp-content/themes/flow/framework/modules/title/title-functions.php on line 417

Convert camelCase to Underscores Using sed

Convert camelCase to Underscores Using sed

This short post deals with converting strings of the form camelCase or CamelCase into camel_case, and vice versa. These are three different popular naming conventions for variable/function/class names.

Convert CamelCase or camelCase to camel_case:

sed -e 's/([A-Z])/_\l\1/g' file.txt
echo "camelCase" | sed -e 's/([A-Z])/_\l\1/g'

Convert camel_case to camelCase

sed -e 's/_([a-z])/\u\1/g' file.txt
echo "camel_case" | sed -e 's/_([a-z])/\u\1/g'

Convert camel_case to CamelCase:

sed -e 's/_([a-z])/\u\1/g' -e 's/^([a-z])/\u\1/g' file.txt
echo "camel_case" | sed -e 's/_([a-z])/\u\1/g' -e 's/^([a-z])/\u\1/g'

Tribute to: AmirWatad.com

Cirjan Dragos
No Comments

Post a Comment