cshin9 cshin9 - 1 year ago 52
Bash Question

How to remove non-letters from a string in script?

I have:

something='sl89wS Gjf-_32b'

I want to return:


How can I make it return only letters and then make everything lowercase?

Answer Source

You can use Parameter Expansion:


here all non-alphabetic characters ([^[:alpha:]]) of variable something will be replaced by none i.e. will be omitted.


$ str='sl89wS Gjf-_32b'
$ echo "${str//[^[:alpha:]]/}"