【发布时间】:2014-10-08 08:04:31
【问题描述】:
我有一个文件,其行如下:
{u'phone_num': u'9999999999', u'name': u'abc', u'format': u'json'}
我正在尝试从每一行中提取电话号码,即 9999999999。
我使用的 sed 不工作。
echo "{u'phone_num': u'9999999999', u'name': u'abc', u'format': u'json'}" | sed 's/.*phone_num.*\([[:digit:]]\+).*/\1/'
这是打印整行,而不仅仅是数字。
【问题讨论】:
-
为什么不用cut呢?
echo "{u'phone_num': u'9999999999', u'name': u'abc', u'format': u'json'}"| cut -d"'" -f 4