Parsing PBX console outputs

I have a problem. I need to parse the following output into something I
can put in a table or two from an old PBX. Each PAD has 1 or more
extensions assigned to it. Extensions should be unique. Here are two
records:

                   D V                           S
                   A M                           P
         RLID      T O  REF  TBL BUZZ            K D

PAD TYPE A D NO. NO. INTERCM VOICE C R T EXTN 1 R MW BI


DS 01/010801 RP400 N RL 0 2 Y N 3441 Y Y Y

CLLD
NAME

DS Y

                   V               V               V               V
                   S   M B         S   M B         S   M B         S

M B
#'S EXTN I R W I EXTN I R W I EXTN I R W I EXTN I
R W I
------ ------- - - - - ------- - - - - ------- - - - - ------- -


DS 2…5 2171 N Y N N 4277 N Y N N

                   D V                           S
                   A M                           P
         RLID      T O  REF  TBL BUZZ            K D

PAD TYPE A D NO. NO. INTERCM VOICE C R T EXTN 1 R MW BI


DS 01/010802 RP400 N RL 0 5 Y N 3768 Y Y Y

CLLD
NAME

DS Y

                   V               V               V               V
                   S   M B         S   M B         S   M B         S

M B
#'S EXTN I R W I EXTN I R W I EXTN I R W I EXTN I
R W I
------ ------- - - - - ------- - - - - ------- - - - - ------- -


DS 2…5 5018 N Y N N 3726 N Y Y N 2324 N Y N N 2396 N
Y N N
DS 6…9 2397 N Y N N 4912 N Y Y N 6718 N Y N N 5060 N
Y N N
DS 10…11 5062 N Y N N 4219 N Y N N

You would need to indicate where the newlines are on this I think,
before anyone could even to even start to help ! (Just a guess from an
old AWK programmer…)

Again as a guess…Probably something like this (might) get you there:

  • Loop the whole on file
  • No need to split all the lines I would say…
  • Look for the word PAD , (record its horizontal position?), toggle on a
    boolean, record the current line number + 2 (to skip the ‘—’ lines)
  • When boolean is on and current line is set to your marker get the PAD
    number, (split the line here probably to extract that PAD number)
  • if boolean on, Look for ‘EXTN’,record the current line number +2
    (again, to skip ‘—’).
    – split the ‘EXTN’ line itself, extract the number, add it to the
    current PAD ( Ruby - maybe a Hash of arrays?: Hash Key:PAD, Arrays of
    extens).

And stuff like this. (probably my logic is off here, but that kinda of
how I would start off…) good luck with that !

J.R. Gutierrez wrote:

I have a problem. I need to parse the following output into something I
can put in a table or two from an old PBX. Each PAD has 1 or more
extensions assigned to it. Extensions should be unique. Here are two
records:

                   D V                           S
                   A M                           P
         RLID      T O  REF  TBL BUZZ            K D

PAD TYPE A D NO. NO. INTERCM VOICE C R T EXTN 1 R MW BI


DS 01/010801 RP400 N RL 0 2 Y N 3441 Y Y Y

CLLD
NAME

DS Y

                   V               V               V               V
                   S   M B         S   M B         S   M B         S

M B
#'S EXTN I R W I EXTN I R W I EXTN I R W I EXTN I
R W I
------ ------- - - - - ------- - - - - ------- - - - - ------- -


DS 2…5 2171 N Y N N 4277 N Y N N

                   D V                           S
                   A M                           P
         RLID      T O  REF  TBL BUZZ            K D

PAD TYPE A D NO. NO. INTERCM VOICE C R T EXTN 1 R MW BI


DS 01/010802 RP400 N RL 0 5 Y N 3768 Y Y Y

CLLD
NAME

DS Y

                   V               V               V               V
                   S   M B         S   M B         S   M B         S

M B
#'S EXTN I R W I EXTN I R W I EXTN I R W I EXTN I
R W I
------ ------- - - - - ------- - - - - ------- - - - - ------- -


DS 2…5 5018 N Y N N 3726 N Y Y N 2324 N Y N N 2396 N
Y N N
DS 6…9 2397 N Y N N 4912 N Y Y N 6718 N Y N N 5060 N
Y N N
DS 10…11 5062 N Y N N 4219 N Y N N

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs