Q:

Using sed to extracting data from file

I have a file with lines like following:
{u'phone_num': u'9999999999', u'name': u'abc', u'format': u'json'}
I am trying to extract the phone number i.e. 9999999999 from each line. 
The sed I am using is not working. 
echo "{u'phone_num': u'9999999999', u'name': u'abc', u'format': u'json'}" | sed 's/.*phone_num.*\([[:digit:]]\+).*/\1/'

This is printing the whole line and not just the digits. 

A:

You can use this sed:
sed "s/^{u'phone_num':[[:blank:]]*u'\([^']*\).*$/\1/" file
9999999999

