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?
$ echo "This is an example: 65 apples" | sed -r 's/^[^0-9]*([0-9]+).*/\1/' 65
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With