Search and remove digits (if exist) from end of the string

Hi Experts,

Here is what I am trying to do.

1) say I have a file with below strings

database1
database2
database3
data10gdb1
data10gdb2
databasewithoutdigit

2) I want to get the below output.
(- if there is any digit at the end of the string, I need to remove it)
(- Any digit which is not at the end of the string shoud remain unchanged)

database
database
database
data10g
data10g
databasewithoutdigit

Thanks
Shelly

sed 's/[0-9]$//' file

Guru.

1 Like
perl -ple 's/\d+$//' file

Superb...Thats why your name is guru. :slight_smile:

I was breaking my head with "sed 's/$[0-9]//'. :slight_smile: