Removing Letters from Integer String

Hi all,

I have a variable, on some machines it is '1024', which is fine, but on others it is '1024Mb' etc. I need this variable to simply be '1024', does anyone know how I could ensure this is always the case? Perhaps a command to remove any letters/characters that aren't integers if there is one?

Thanks.

Well, you could use

echo "1024MB" | awk '{print substr($1,0,4)}' # print first four numbers / chars
echo "1024MB" | sed 's/[A-Za-z]*//g'         # removes all letters
x=${x%%[A-Za-z]*}           # remove everything after (and including) any chars

Assuming sh, ksh, zsh (, bash?):

y=1024
z=1024Mb
sizey=`expr "$y" : '\([0-9][0-9]*\)'`
sizez=`expr "$z" : '\([0-9][0-9]*\)'`

$sizey and $sizez will now both be 1024.

Note that oombera's third solution depends on ksh.

Try this:
echo 1245MB |tr -d [A-Z][a-z]

-Yeheya