Print proplist=!comment

Hi there

i’m trying to print a tabular view of statistics, such as:

“/interface/ print stats proplist=rx-drop,tx-drop”

but somehow “comments” are always present, and in newline, completelly breaking tabulation

sample output:

[admin@CRS] /interface> print stats proplist=rx-drop,tx-drop,type,default-name
Flags: R - RUNNING; S - SLAVE
Columns: RX-DROP, TX-DROP, TYPE, DEFAULT-NAME
 #    RX-DROP  TX-DROP  TYPE      DEFAULT-NAME
;;; TX-6.0db;;RX-7,9db
 0  S                   ether     sfp-sfpplus1
 1 RS                   ether     sfp-sfpplus2
 2 RS                   ether     sfp-sfpplus3
;;; TX+2,7db;;RX-6,0db
 3 RS                   ether     sfp-sfpplus4
;;; TX+3,7;;RX-16,8db
 4 RS                   ether     sfp-sfpplus5
;;; AOC
 5 RS                   ether     sfp-sfpplus6
;;; AOC
 6 RS                   ether     sfp-sfpplus7
;;; TX+2,5db;;RX-12,34db
 7 RS                   ether     sfp-sfpplus8
;;; TX+2,9db;;RX-13.05db
 8 RS                   ether     sfp-sfpplus9
;;; TX+3,7db;;RX-17.14db
 9 RS                   ether     sfp-sfpplus10
;;; TX+3,2db;;RX-9.72db
10 RS                   ether     sfp-sfpplus11
;;; TX -6,1db;;RX -11.4db
11 RS                   ether     sfp-sfpplus12
12 RS                   ether     sfp-sfpplus13
13                      ether     sfp-sfpplus14
14 RS                   ether     sfp-sfpplus15
;;; AOC
15 RS                   ether     sfp-sfpplus16
;;; debug
16                      ether     ether1
17 R        0        0  bridge
18          0        0  bond
19 RS       0        0  bond
20 RS       0        1  bond
21 RS       0        0  bond
22 RS       0        0  bond
23 RS       0      352  bond
24 RS       0        0  bond
25 RS       0        4  bond
26 RS       0        0  bond
27 RS       0        0  bond
28 R        0        0  loopback
29 R        0        0  vlan
30 R        0        0  vlan

I couldn't do what you wanted!
I tryed:

[repeatedly.censored@mybox] > :grep script="/interface/print detail stats proplist=rx-drop,tx-drop,type,default-name" pattern!=";;;"

But the result was quite predictable...

expected end of command (line 1 column 89)

But I could do exactly the opposite of what you want.

:grep script="/interface/print detail stats proplist=rx-drop,tx-drop,type,default-name" pattern=";;;"

But I believe this can be a path to reach what you want.
In this impoverished version of RouterOS's grep there is no "-v" or "--invert-match".
Maybe if you put your efforts into getting ":grep" inside RouterOS to have the argument

invert-match (yes | no; Default: no)

it will be easier to achieve what you want, and most likely this will work in many other scenarios.

This might work:

 :grep script="/interface/print detail stats proplist=rx-drop,tx-drop,type,default-name" pattern="^[^;]"

That drops lines starting with ;. If you want to be pedantic and only drop lines that start with ;;; then:

 :grep script="/interface/print detail stats proplist=rx-drop,tx-drop,type,default-name" pattern="^([^;]|(.[^;])|(..[^;]))"

Good! Good!

You actually worked on inverting matches in Regex.
An elegant solution to the lack of the necessary feature.

But... The idea of ​​invert-match (yes | no; Default: no) would be good, and useful in many other cases... that would be it!

This is beautifull!

But still, a very roundabout way to make pigs fly

simple stuff like "print interfaces brief no-comments" should not require such a level of hackery

I agree, and :grep should be extended with invert-match too as @fischerdouglas wrote above.

Besides, my Regex missed the cases where the line contains just the string ; or ;; and nothing else. That shows how trying to manually invert Regex patterns is very error prone :face_with_diagonal_mouth:. A more correct pattern is:

:grep script="/interface/print detail stats proplist=rx-drop,tx-drop,type,default-name" pattern="^(.{0,2}[^;])|^(;{1,2})\$"

And it quickly looks messy.

I'm not a big fan of grep, at least in RouterOS.

You can use :serialize to=dsv options=dsv.remap [/interface/print detail stats proplist=rx-drop,tx-drop,type,default-name] if goal is to for output to something other than terminal.

Also, you just use a simple script to store the results of /interface/print detail stats as-value and then use a :foreach loop to output to screen as va however you want.

Otherwise, you run into the limited support for string parsing in RouterOS scripting. But you can always get an array from print ... as-value then access whatever variables you want.