transposing letters

Hi, I've written a shell function in bash that reads letters into an array, then outputs them in one column with:

for n in "${array[@]}"; do
echo $n
done

I was wondering if anyone knew how i would transpose the letters that are output by the for loop. Right now my output is:

aabbcc
ddeeff
gghhii

ex...if I input 'aabbcc ddeeff gghhii' into the array, is it possible to transpose them and output:

ccbbaa
ffeedd
iihhgg

can i use sed?

thanks.

Perhaps use "rev"

I would use rev, but i don't want to reverse the whole string...

say the input is xxyyzz, i want to keep 3 pairs of 2, and swap the xx and the zz, keep the yy in the same place, and keep the characters in the same order within their pairs...another example, say i have 123456, it would be output as 563412.

thanks.

Then perhaps you agree that your example data could have been clearer! You could use awk...

$ echo 123456| awk '{for(x=1;x<=length;x+=2)s=substr($0,x,2) s}END{print s}'
563412

Ygor-

my appologies on the example then, i realized that you could use rev on aabbcc after you said it :wink:

that works great, thank you so much!