Bash – Extract integer from string using bash

bashintegerstring

I tried to find the solution here but could not; given strings like

ABC3
DFGSS34
CVBB3

how do I extract the integers so I get

3
34
3

??

Best Solution

Just a simple sed command will do the job:

sed 's/[^0-9]//g' file.txt

OUTPUT

3
34
3