0

我得到了这样的标准输出。

Queues
  queue                                          dur  autoDel  excl  msg   msgIn  msgOut  bytes  bytesIn  bytesOut  cons  bind
  ==============================================================================================================================
  14531c8d-dd9b-4f41-9d92-c1344774d21c:0.0            Y        Y        0     0      0       0      0        0         1     2
  qmfagent-425fa29c-0892-4c08-a2d9-e7331a37dc13       Y        Y        0     0      0       0      0        0         1     4

所以我需要解析这个输出并且只得到这样的东西

14531c8d-dd9b-4f41-9d92-c1344774d21c:0.0
qmfagent-425fa29c-0892-4c08-a2d9-e7331a37dc13

谁能告诉我如何做这个红宝石?当然可以有更多的行。

4

2 回答 2

0

用换行符 ( ) 分割行\n。获取最后两行。

output = <<EOD
Queues
  queue                                          dur  autoDel  excl  msg   msgIn  msgOut  bytes  bytesIn  bytesOut  cons  bind
  ==============================================================================================================================
  14531c8d-dd9b-4f41-9d92-c1344774d21c:0.0            Y        Y        0     0      0       0      0        0         1     2
  qmfagent-425fa29c-0892-4c08-a2d9-e7331a37dc13       Y        Y        0     0      0       0      0        0         1     4
EOD

lines = output.strip.split("\n") # Split lines by newline
last_two_lines = lines[-2..-1] # Get the last 2 lines.
p last_two_lines.map {|line| line.split[0]} # Get the first fields.

印刷

["14531c8d-dd9b-4f41-9d92-c1344774d21c:0.0", "qmfagent-425fa29c-0892-4c08-a2d9-e7331a37dc13"]
于 2013-08-19T09:39:40.703 回答
0
queues = <<EOS
queue                                          dur  autoDel  excl  msg   msgIn  msgOut  bytes  bytesIn  bytesOut  cons  bind
==============================================================================================================================
14531c8d-dd9b-4f41-9d92-c1344774d21c:0.0            Y        Y        0     0      0       0      0        0         1     2
qmfagent-425fa29c-0892-4c08-a2d9-e7331a37dc13       Y        Y        0     0      0       0      0        0         1     4
EOS

queues.lines.each {|line|
  puts line.split.first if line =~ /[[\da-f]]{4}/i    # detects 4 consecutive hexadecimals
}
于 2013-08-20T00:25:56.023 回答