I would like to know if there is a way or a script that would allow me to read a text string and then output it in reverse order.
Example:
for i in `cat $1`
do
print $i
done
If i in is "Test" I would like the output to be "tseT"
There is probably a way Perl or awk, but how about converting the string to an array of letters, and looping backwards through it: #!/bin/ksh
string="$*"
integer i=${#string}
set -A arrayvar $(print $* | sed 's/./& /g')while (( i >= 0 ))
do
print -n ${arrayvar[$i]}
(( i -= 1 ))
done
That was a great answer, I knew there had to be a real easy way to do it. Thanks
That's weird. It would appear that I am answering myself (Oh, am I?). The previous post appears to have come from me, but it was not my reply. The name is slightly misspelled, but click on the link and you see my e-mail address. OK, who did that?
| « Unix for PC ? | shell script help! » |