Remove underscore and capitalize character after it Remove underscore and capitalize character after it unix unix

Remove underscore and capitalize character after it


Your suggestion 's/_/\U\1/g' is very close. If you have the GNU sed, then the following should work:

sed 's/_\(.\)/\U\1/g'

(I say should, because what you wish for is not always what you want.)


Perl script:

use String::CamelCase qw(camelize);while (<>) {  print camelize($_);}


Little more verbose from awk but it will work on all gnu/non-gnu Unix flavors:

> s='get_employee_Name'> awk -F _ '{printf "%s", $1; for(i=2; i<=NF; i++) printf "%s", toupper(substr($i,1,1)) substr($i, 2); print"";}' <<< "$s"getEmployeeName