Aqui estão algumas maneiras:
sed 's/^[^0-9]*\([0-9]\+\).*//' test
cat test | tr -c '0-9\n' ' ' | while read first rest; do echo $first; done
gawk -F '[^0-9]+' '{print $2}' test # requires non-digits to start line
perl -nE'say/(\d+)/?$1:""' test # code golf
bash:
while read line; do [[ $line =~ [[:digit:]]+ ]] && echo ${BASH_REMATCH[0]} || echo; done