Vinay Shukla
Vinay Shukla

Reputation: 1844

Separate number from a alphanumeric

I want to remove M from

82M

how can I do it in a shell script

var=82M 

Wanted value

var1=82

Upvotes: 0

Views: 306

Answers (2)

fedorqui
fedorqui

Reputation: 289815

Many ways to remove non numeric characters:

$ v=82M
$ echo "$v" | tr -cd '0-9'
82
$ echo "$v" | sed 's/[^0-9]//g'
82

Upvotes: 0

anubhava
anubhava

Reputation: 785256

Using BASH's string manioulation:

var=82M
var1="${var//[^0-9]*}"
echo "$var1"
82

OR using tr:

tr -d '[[:alpha:]]' <<< "$var"
82

Upvotes: 1

Related Questions