2

我有一个文件网址,输出如下:

//
data = {
    'ip': '',
    'server_ip': '',
    'router_name': 'Banana Hammock',
    'wan_domain': '',
    'wan_gateway': '74.125.224.32',
    'wan_gateway_get': '74.125.224.32',
    'wan_get_domain': 'isp.example.com',
    'wan_hostname': 'MumbaVille',
    'wan_hwaddr': '00:00:00:00:00:00',

我正在使用这个命令来获取 wan_gateway_get:

curl -k http://mumbarouter.com/get.asp?statits | awk '/wan_gateway_get/ {print $2}'

输出:

'74.125.224.32',
=

我怎样才能让它输出:

74.125.224.32

谢谢你,祝妈妈快乐!

4

3 回答 3

2

让自己轻松一点……因为分手很容易做到:

curl -k http://mumbarouter.com/get.asp\?statits |
  awk -F\' '/wan_gateway_get/ {print $4}'
于 2012-05-15T17:25:33.530 回答
1

以下

awk '/wan_gateway_get/ {match($2, "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"); print substr($2,RSTART,RLENGTH)}'

是可能的方式之一。

于 2012-05-15T17:25:55.940 回答
0

TXR解决方案:对实际语法进行自由格式解析。(强制右括号添加到示例数据。)

@(define comment)//@nil@\n@(end)
@(define ws)@(cases)@(comment)@(or)@/\s*/@(end)@(end)
@(define id (id))@(ws)@{id /\w[\w\d_]+/}@(ws)@(end)
@(define item (it))@(ws)'@{it /[^']+/}'@(ws)@(end)
@(define braced_key_values (ithash))@\
  {@(coll)@(item key):@(item value)@(until)}@(end)}@\
  @(bind ithash @(progn '#H((:equal-based) ,*[mapcar list key value])))@\
@(end)
@(freeform)
@(id config)@(ws)=@(ws)@(braced_key_values config-hash)
@(output)
wan_gateway in configuration "@config" is @[config-hash "wan_gateway"]
@(end)

跑:

$ txr data.txr data.txt
wan_gateway in configuration "data" is 74.125.224.32
于 2012-05-15T20:57:44.963 回答