Solution will not work if line has multiple words including space

cat input | grep -o '[0-9]*'

Above solution will not work if a line has multiple words with space between them.However the solution below will work in every case:

grep '[0-9]' file.txt | tr -d '[a-z]' 

If you want to save the output in file like in question

grep '[0-9]' file.txt | tr -d '[a-z]'  > file