Question

match two lines with different amounts of output

  • 25 March 2024
  • 2 replies
  • 48 views

Userlevel 3
Badge

I have a problem where the two lines of this module output are not the same.  How can I put in essentially null place holders so that they resultant patterns are the "same"?

example output
Notice that module 2 does not have Fw or Sw.

Mod MAC addresses                    Hw  Fw           Sw               Status
1 a03d.6f81.0740 to a03d.6f81.074f 1.1 15.0(1r)SG12 03.07.03.E Ok
2 b0aa.777d.d010 to b0aa.777d.d017 1.0 Ok

 


I was trying to use these two patterns and tried to put in placeholds of Fw and Sw at the end of "pattern03".  But the NQE does not like this.

pattern02 =
```
Mod MAC addresses
{modNum:number} {string} to {string} {hwVer:string} {fwVer:string} {swVer:string} {modStatus:string}
```;

pattern03 =
```
Mod MAC addresses
{modNum:number} {string} to {string} {hwVer:string} {modStatus:string} {fwVer: null:string} {swVer: null:string}
```;

getMacAddrList(parsedOutput) =
foreach pattern in [pattern02, pattern03]
foreach match in blockMatches(parsedOutput, pattern)
select match;

 


2 replies

It appears that the output you are trying to parse is a fixed format.  I do realize that tabs and other non-printing characters might be lurking in the output but perhaps you can assume the row is “oneBigString” and use Sting functions to grab just certain data chunks.  Say anything from position X in the oneBigString for Y characters is a particular dataValue.

Userlevel 3
Badge

I chose to use two different user functions.  One had a pattern to match all columns.  The other to match output with two missing columns.  If there is ever a third, then I will be out of luck.

But then in the second user function.  In the Select statement.  I could add “columnX: null:String” and “columnY: null:String”.  Now all of the columns are accounted for and I can now add those two lists together.

Reply