Changing the character after the Underscore(_)

Hi Everyone,

I am looking for a command that would do the following:

1) Change all the letters/words in a file to Lower case Letters/words.
2) Remove the Underscore () and Change the Character after the underscore () to an Uppercase letter.

Example:

File contains the below words:

FILTER_WORD
USA_NEWJERSEY
USA_NEWYORK_NYC

Output should be:
filterWord
usaNewjersey
usaNewyorkNyc

It would be really helpful if someone could help me out achieving this.

Thanks a lot for all your time!!!

$ perl  -alne '$_=~s/_/ /g; $_=~s/(\w+)/\u\L$1/g;$_=~s/ //g;print lcfirst $_' input.txt
filterWord
usaNewjersey
usaNewyorkNyc
1 Like
perl -pe '$_=lc;while(/_([a-z])/g){$x=$1;$y=uc($x);s/_$x/$y/g}' inputfile
1 Like

Hi,

Here is the awk solution,

 awk '{$0=tolower($0);while(match($0,"_")){l=substr($0,match($0,"_"),2);L=toupper(l);sub(l,L);sub(/_/,"");}}1' file

Cheers,
Ranga:)

1 Like

Thank you very much for all your quick replies.

Its really helpful.

Shorter:

perl -pe '$_=lc;s/_([a-z])/\u$1/g' inputfile
1 Like