Solved

# Convert base 10 number to Base 62 within a shell script.

Posted on 2005-03-26

Convert base 10 number to Base 62 within a shell script.

VAR_1="2938567234976527896527965"

(your input suggestion)

echo $VAR_2

(some alphanumeric string)

I have looked high and low for base 62 convertors as at least examples.

The numbers to be converted within a bash script (I'll add it as a function i think) are really really big/long. I want these numbers converted to base 62 (A-Z,a-z,0-9)

NOTE: some of these number start with a "0" ie: 0387465278652786521 This can be ignored, just wanted to forewarn ya, in case it effects the smoothness I'd like to see ;)

further stuff ... this is the function that makes the number in the first place.

random_string()

{

RAND_1=`cat /dev/random | od | head -n 1`

RAND_2="$RANDOM"

RAND_3=`date +%N`

echo -n $RAND_1 > tmp.data

echo -n $RAND_2 >> tmp.data

echo -n $RAND_3 >> tmp.data

sed 's/ //g' tmp.data > tmp.data2

cat tmp.data2 > tmp.data

sort tmp.data > tmp.data2

uniq tmp.data2 > tmp.data

TMP=`cat tmp.data | sed 's/0000000//g' | sed 's/000//g'`

echo $TMP

}