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:
1 | sed -e 's/\([A-Z]\)/_\l\1/g' -e 's/^_\([a-z]\)/\1/g' file.txt |
Convert camel_case to camelCase
1 | sed -e 's/_\([a-z]\)/\u\1/g' file.txt |
Convert camel_case to CamelCase:
1 | sed -e 's/_\([a-z]\)/\u\1/g' -e 's/^\([a-z]\)/\u\1/g' file.txt |
No related posts.
5 Comments to Convert camelCase to Underscores Using sed
Leave a Reply
About Me
Tags
Bash
Collaboration
Command Line Interface
Courses
Debug
Ebooks
Email
Facebook
Firefox
Gnome
Google
Hardware
Illusions
Linux
Linux Development
Macros
Manpages
Multimedia
Networks
Object Oriented Programming
Off-Topic
Open Knowledge
Operating Systems
Productivity
Programming
Religion
Science
Security
sed
Sharing
Shell Scripts
Short Posts
Small Code
Social Media
Studies
Terminal
TIps
Tools
Troubleshooting
Ubuntu
University
Vim
Web Development
Web Services
Websites
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Calendar
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)

Thanks for sharing this Amir.
Would it be possible to carry out the following in one script or command?
camelCase => camel_case
camelCaseLong => camel_case_long
camelCaseXYZ => camel_case_xyz
CamelCase => Camel_Case
CamelCaseLong => Camel_Case_Long
CamelCaseXYZ => Camel_Case_XYZ
I’m open to all suggestions.
Many thanks,
Michael
This does half of the job:
Will try to find a complete solution as soon as I have time.
I look forward to a full solution.
Thanks again Amir.
AFAIK
TcpListener– this is PascalCase
tcpListener — this is camelCase
Another solution to convert camel_case to CamelCase:
sed -e ‘s/\(^\|_\)\(.\)/\U\2/g’