3.21以后版本增加了查询命令
Queries print command accepts query words that limit set of returned items. This feature appeared in the 3.21 version.
Query words begin with '?'.
Order of query words is significant. Query is evaluated starting from the first word.
Query is evaluated for each item in the list. If query succeeds, item is processed, if query fails, item is ignored.
Query is evaluated using a stack of boolean values. Initially stack contains infinite amount of 'true' values. At the end of evaluation, if stack contains at least one 'false' value, query fails.
Query words operate according to the following rules:
?name pushes 'true' if item has value of property name, 'false' if it does not.
?-name pushes 'true' if item does not have value of property name, 'false' otherwise.
?name=x
?=name=x pushes 'true' if property name has value equal to x, 'false' otherwise.
?<name=x pushes 'true' if property name has value less than x, 'false' otherwise.
?>name=x pushes 'true' if property name has value greater than x, 'false' otherwise.
?#operations applies operations to the values in the stack.
operation string is evaluated left to right.
sequence of decimal digits followed by any other character or end of word is interpreted as a stack index. top value has index 0.
index that is followed by a character pushes copy of value at that index.
index that is followed by the end of word replaces all values with the value at that index.
! character replaces top value with the opposite.
& pops two values and pushes result of logical 'and' operation.
| pops two values and pushes result of logical 'or' operation.
. after an index does nothing.
. after another character pushes copy of top value.
Examples:
Get all ethernet and VLAN interfaces:
/interface/print
?type=ether
?type=vlan
?#|
Get all routes that have non-empty comment:
/ip/route/print
?>comment= |