Page 1 of 1

SOLVED : Bash remove trailing digits

Posted: Fri Jan 05, 2018 12:57 pm
by mister_v
Hi,

How can I remove trialing digits from a string ?

this 5
test 556
test5

thank you.

Re: Bash remove trailing digits

Posted: Tue Jan 09, 2018 10:06 pm
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'`;

Re: Bash remove trailing digits

Posted: Thu Jan 11, 2018 2:56 pm
by chris
Thanks that is what I was looking for :-)