文本文件解析

时间:2011-09-20 02:16:07

标签: ruby parsing awk gawk rgl

我有很多文本文档都填充了sudo表,如下例所示。将表解析为散列或数组之类的最佳方法是什么?

我是编写自定义算法还是现有库?

PLACE  NO.  NAME                    DIV    RANK  SWIM  TRANS RANK  BIKE   MPH   TRANS RANK   RUN   PACE  TIME    
===== ===== ======================= ===    ====  ====  ===== ==== ======= ===== ===== ====  ====== ===== ======= 
    1     1 Krige Schabort          PCHAL    3   22:40  1:08   25 1:14:15 20.2  2:25    1   26:24  4:24 2:06:49                
    2    12 Kevin Moats             M5559   11   24:41  0:46    1 1:06:01 22.7  0:44    9   42:50  7:09 2:15:00                

2 个答案:

答案 0 :(得分:3)

您可能想尝试slither

答案 1 :(得分:1)

如果格式是长度固定的并且填充了空格,那么String#unpack

您可能会看到http://ruby-doc.org/core/classes/String.html#M001112了解详情