Search code examples
bashawkgrepgnuwin32

Remove digits from end of string


I want to remove digits from end of a string.

Example:

 string123
 example545

Output:

string
example

Solution

  • Provided you have no other digits anywhere else in the string you can do:

    echo string123 | sed 's/[0-9]//g'
    string
    

    And only the end of the string:

    echo S1tring123 | sed 's/[0-9]\+$//'
    S1tring
    

    Where $ indicates the end of the line.