print in reverse order

Hi,

I want to print the item in reverse order such that the output would look like

00 50 50 23 40 22 02 96

Below is the input:

00 05 05 32 04 22 20 69
echo "00 50 50 23 40 22 02 96" | perl -ane '@F = map { scalar reverse } @F; print "@F"'

Thanks man, but i don't know perl

found a way using shellscript

#Check for the number or words
w_cnt=`cat <file> | wc -w`

#Initialized cnt and proceed with while loop
cnt=1
while [ $cnt -lt $w_cnt ]
do
   rev_order=`cut -d' ' -f${cnt} <file> | rev`
   echo $rev_order
   cnt=$((cnt+1))
done > final_order

awk '{printf("%s",$0)}' final_order

this will give you an output of
00505023402202

Regards,

Hi

Using awk:

$ echo 00 50 50 23 40 22 02 96 | awk '{for(i=1;i<=NF;i++){split($i,a,"");x=x a[2]""a[1] FS}}END{print x}'

With modern bash:

for x in 00 50 50 23 40 22 02 96; do echo -e "${x#[0-9]}${x%[0-9]} \c"; done

With rev (much slower):

for x in 00 50 50 23 40 22 02 96; do echo -e "$(echo $x | rev) \c"; done

can you explain me how echo -e "${x#[0-9]}${x%[0-9]} \c" works?

Thanks,