Artificial intelligent assistant

Extracting string up to first digit in Bash I would like to find a straightforward method to extract the portion of a string up to where the first digit appears (possibly using regular expressions instead of traversing the string character by character). I am using this to extract package names from `rpm -qa` without their versions. E.g: Parsing: perl-Text-ParseWords-3.30-1.fc22.i686 Result: perl-Text-ParseWords

# Preferred Alternative

We could simply modify the rpm query to only output the name.


rpm -qa --queryformat "%{NAME}\
"


**Or we can get dirty with a regex**

Not exactly "straight forward" but here is a sed regex that should be able to do it.


sed -e 's/\([^\.]*\).*/\1/;s/-[0-9]*$//' <<< "perl-Text-ParseWords-3.30-1.fc22.i686"


This should handle everything except for in there is a period in the package name (I don't even think that is allowed).

**Quick breakdown**

* `s/\([^\.]*\).*/\1/` grab everything before the first period. So `perl-Text-ParseWords-3.30-1.fc22.i686` becomes `perl-Text-ParseWords-3`

* `s/-[0-9]*$//`get rid of that trailing `-` and first version digit. So `perl-Text-ParseWords-3` becomes `perl-Text-ParseWords`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy ac36ebc8bad4ae46c6ce45d3fa7c0df9