SOLVED : Bash remove trailing digits

Bash shell is the common linux command language.
Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

SOLVED : Bash remove trailing digits

Post by mister_v »

Hi,

How can I remove trialing digits from a string ?

this 5
test 556
test5

thank you.
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Bash remove trailing digits

Post by chris »

You can use

Code: Select all

VARIABLE="test 556";

VARIABLE=${VARIABLE//[0-9]/};
But this will remove all digits not only at the end.

Better is to use sed

Code: Select all

VARIABLE=`echo $VARIABLE | sed -e 's/[0-9]*$//g'`;
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Bash remove trailing digits

Post by chris »

Thanks that is what I was looking for :-)
Post Reply