字符串输出某列

来源:互联网 发布:php zrem 编辑:程序博客网 时间:2024/04/30 11:30

如有这么一个字符串

rs ="        Interface                 PHY      Protocol  InUti  OutUti   inErrors  outErrors                                                            10GE1/0/1                  up       up        99.0% 99.0%                1          2                                                            10GE1/0/2                  up(l)    up           0%     0%                   0          0                                                            10GE1/0/3                  up(l)    up           0%     0%                  3          0                                                            10GE1/0/4                  up(l)    up        0.03%     0%                0          4"

我要提取出inErrors 和 outErrors 这两列的数据 并放入数组中 [["1", "2"], ["0", "0"], ["3", "0"], ["0", "4"]]

require 'csv'_, *rows = CSV.parse rs.strip, col_sep: ' 'rows.map {|r| r.values_at 5, 6 }
rs.scan(/\s(\d+)\s+(\d+)\s*$/)

0 0