Converting text to certain format

Hi Forum.

I'm trying to convert the following text using "sed" or "awk" or "tr" but with no luck.

From:
EDW_WHOLESALE_VORTEX

To:
[Ee][Dd][Ww]_[Ww][Hh][Oo][Ll][Ee][Ss][Aa][Ll][Ee]_[Vv][Oo][Rr][Tt][Ee][Xx]

Any help is greatly appreciated.

$ echo "EDW_WHOLESALE_VORTEX" | awk -F "" '{ 
>   for(i=1;i<=NF;i++) {
>       if (toupper($i) != tolower($i))
>       printf "["toupper($i)tolower($i)"]"
>   else printf $i;
>   }
>   printf "\n";
>   }'
[Ee][Dd][Ww]_[Ww][Hh][Oo][Ll][Ee][Ss][Aa][Ll][Ee]_[Vv][Oo][Rr][Tt][Ee][Xx]

You try the below...

echo "EDW_WHOLESALE_VORTEX" |\
awk '{
 for (i=0; i <= length($0); i++) 
 {
  if (substr($0, i, 1) != "_")
   printf "[%c%c]", toupper(substr($0, i, 1)), tolower(substr($0, i, 1));
  else
   printf "%c", substr($0, i, 1);
 }
  print "";
}'
echo 'EDW_WHOLESALE_VORTEX' | nawk '{for(i=1;i<=length;i++) {c=substr($0,i,1);printf("%s%c", (tolower(c)~/[a-z]/)?"[" toupper(c) tolower(c) "]":c, (i==length)?ORS:"")}}'
echo 'EDW_WHOLESALE_VORTEX' | 
awk -F "" '{
  for(i=1;i<=NF;i++){
    if($i=="_"){
      printf $i
    }
    else {
      printf("[%s%s]", $i, tolower($i))
    }
  }
  print ""
}' 
[Ee][Dd][Ww]_[Ww][Hh][Oo][Ll][Ee][Ss][Aa][Ll][Ee]_[Vv][Oo][Rr][Tt][Ee][Xx]
awk 'BEGIN{FS=OFS=""}function f(_){return "["$i tolower($i)"]"}{for(i=0;++i<NF;){if($i~/[A-Z]/)$i=f($i);printf $i};print f($i)}' file

thanks guys for your quick responses. I will give it a try.

I kinda like this:

echo "EDW_WHOLESALE_VORTEX" | perl -pe 's/([a-zA-Z])/[\u$1\l$1]/g'
[Ee][Dd][Ww]_[Ww][Hh][Oo][Ll][Ee][Ss][Aa][Ll][Ee]_[Vv][Oo][Rr][Tt][Ee][Xx]

TMTOWTDI!

Nathan

Nice, this will also work in GNU sed:

sed 's/[[:alpha:]]/[\u&\l&]/g'

I like the gnu sed even better.. very simple and clean