Alphanumeric to integer

Hi folks,

I have a value like A12,i could able to change this into integer using typeset as below
typeset -i A12

But, I need your advice to change the values like 1A2 or 12A into integer.

Thanks in advance.

Thanks,
Sathish

Depends on whether you want 1A2 to return 1, 2 or 12

If the latter,

sed 's/[^0-9]+//g' 

If the former,

 perl '@ints=$ARGV[0]=~/[0-9]+/g;print(join ", ", @ints),"\n";'

Thanks for your reply.

I dont not want to split the value.I want it as whole 1A2 into integer.

I want to use this value in array index as belue

Array[1A2] - now i am getting error like "bad number"

So i need to change 1A2 into integer.

Please advice.

Thanks,
Sathish

Is it hexadecimal?

Depending on your shell and system, you may be able to turn it into decimal like

VAL=1A2
VAL=$((0x${VAL}))

If it's not hexadecimal, you'll need to explain how you want the numbers interpreted, since arbitrary string to integer isn't straightforward.