# Parsing PBX console outputs

**URL:** <https://www.ruby-forum.com/t/parsing-pbx-console-outputs/147243>\
**Category:** Ruby\
**Created:** [August 29, 2008, 7:04pm UTC](https://www.ruby-forum.com/t/parsing-pbx-console-outputs/147243 "2008-08-29T19:04:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrgutier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jrgutier](https://www.ruby-forum.com/u/jrgutier)\
**Post date:** [August 29, 2008, 7:04pm UTC](https://www.ruby-forum.com/t/parsing-pbx-console-outputs/147243/1 "2008-08-29T19:04:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jrgutier](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b3f665/32.png) [@jrgutier](https://www.ruby-forum.com/u/jrgutier)\
**Post date:** [August 29, 2008, 9:36pm UTC](https://www.ruby-forum.com/t/parsing-pbx-console-outputs/147243/2 "2008-08-29T21:36:03Z")

</div>

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
