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/
What you are seeing is the greedy behavior of regex. In your first example, .*
gobbles up all the digits. Something like this does it:
echo "This is an example: 65144 apples" | sed -n 's/[^0-9]*\([0-9]\+\) apples/\1/p'
65144
This way, you can't match any digits in the first bit. Some regex dialects have a way to ask for non-greedy matching, but I don't believe sed
has one.