Swapping a string of numbers between higher and lower order values(HEX)

I have this below string in a variable

cutString=21222222222222222122222222222222

this string is nothing but hex values depicted as below

 
21:22:22:22:22:22:22:22:21:22:22:22:22:22:22:22

so what i want to achieve is swap the lower order with higher order values in the string

21222222222222222122222222222222
 
output: 
12222222222222221222222222222222
 

let me give you another exaample

12345678901234567890123456789012
 
output:
21436587092143658709214365870921
 

also i need to do one more implementation

first i need to store this convertted output in one variable say nextString

later i need to introduce a space between each byte as below so that i can loop it in for loop and perform some operation..(PS: there shouldnt be an extra space at the end of string)

2 1 4 3 6 5 8 7 0 9 2 1 4 3 6 5 8 7 0 9 2 1 4 3 6 5 8 7 0 9 2 1

any help is deeply appreciated. thanks.

even if i can just learn how to introucde spaces, i can handle swapping in for loop by myself. :slight_smile:

Like so?

sed 's/\(.\)\(.\)/\2 \1 /g'
1 Like

or sth like this..

 
echo "12345678901234567890123456789012" | rev | sed 's/./& /g'

Thanks a lot Scrutinizer.. the command works good :slight_smile:

@pamu.. thanks but that code is reversing the whole string and not higher value to lower value. but thanks anyway :slight_smile: