Sed to grep only numbers in string

Hi,

I would like to get only number in the following strings.

var1="Type20"
var2="type 3"
var3="value 2"
var4="Type 1 Datacenter Hall 2"

I would like to extract output as 20 from var1 and 3 from var2,2 from var3 and 1 from var4.

Appreciate any one help asap..

Regards,
Aji

> echo "Type 20" | tr -d " " | tr -s "[:alpha:]" "~" | cut -d "~" -f2
20

> echo "Type 1 Datecenter Hall 2" | tr -d " " | tr -s "[:alpha:]" "~" | cut -d "~" -f2
1

Nice use of the worm character :stuck_out_tongue:

$ cat file
var1="Type20"
var2="type 3"
var3="value 2"
var4="Type 1 Datacenter Hall 2"
$ sed 's [^"]*[^0-9]*\([0-9]*\).* \1 ' file
20
3
2
1

I have found out the solution my self and works fine..thanks for my self ..:stuck_out_tongue:

nimbld1:root:/home/users/thayata/cvs/test # var="Type 3"
nimbld1:root:/home/users/thayata/cvs/test # print $var |tr -d '[A-Za-z]' |sed 's/ //g'
3
nimbld1:root:/home/users/thayata/cvs/test #

What about var4 ? Your solution will return 12
Take radoulov solution.