Issue
I have tried to extract a number as given below but nothing is printed on screen:
echo "This is an example: 65 apples" | sed -n 's/.*\([0-9]*\) apples/\1/p'
However, I get '65', if both digits are matched separately as given below:
echo "This is an example: 65 apples" | sed -n 's/.*\([0-9][0-9]\) apples/\1/p'
65
How can I match a number such that I don't know the number of digits in a number to be extracted e.g. it can be 2344 in place of 65?
Solution
$ echo "This is an example: 65 apples" | sed -r 's/^[^0-9]*([0-9]+).*/\1/'
65
Answered By - codaddict Answer Checked By - Willingham (WPSolving Volunteer)