Searching for a String in the Output
You can filter the output to search for a text matching a regular expression. You can match a regular expression, match everything except a regular expression, or find the first occurrence of text matching a regular expression. All searches are not case-sensitive.
To ignore text that matches a regular expression, specify the
exceptcommand after the pipe:user@host>command| exceptregular-expressionTo find the first occurrence of a regular expression, specify the find command after the pipe:
user@host>command| findregular-expressionTo match a regular expression, specify the
matchcommand after the pipe:user@host>command| matchregular-expressionIf the
regular-expressioncontains any spaces, operators, or wildcard characters, enclose it in quotation marks.You use extended regular expressions to specify what text in the output to match. Command regular expressions implement the extended (modern) regular expressions as defined in POSIX 1003.2.
Table 5 lists common regular expression operators.
Table 5: Common Regular Expression Operators
For example, if a command produces the following output:
one twotwo twothree two onefourThe
match twocommand displays:one twotwo twothree two oneThe
except onecommand displays:two twofourList all the ATM interfaces in the configuration:
user@host>show configuration | match at-at-2/1/0 {at-2/1/1 {at-2/2/0 {at-5/2/0 {at-5/3/0 {Display a skeleton of your router configuration:
[edit]user@host# show | match {system {root-authentication {name-server {login {class superuser {user junipero {authentication {services {syslog {file messages {processes {chassis {alarm {sonet {images {scb {fpc {interfaces {at-2/1/1 {atm-options {unit 0 {at-2/2/0 {...snmp {community public {clients {routing-options {static {route 0.0.0.0/0 {route 192.168.0.0/16 {route 208.197.169.0/24 {protocols {rsvp {interface so-5/1/0 {mpls {interface so-5/1/0 {bgp {group internal {ospf {area 0.0.0.0 {interface so-5/1/0 {List all users who are logged in to the router except for the user "root":
user@host>show system users | except root8:28PM up 1 day, 13:59, 2 users, load averages: 0.01, 0.01, 0.00USER TTY FROM LOGIN@ IDLE WHATsheep p0 baa.juniper.net 7:25PM - cliSave the configuration, except for encrypted passwords, to a file:
user@host>show configuration | except SECRET-DATA | save my.output.fileDisplay the output, starting not at the beginning but rather at the first occurrence of text matching a regular expression, using the
findcommand after the pipe:user@host>command| findregular-expressionIf the regular expression contains spaces, operators, or wildcard characters, enclose the expression in quotation marks.
List the routes in the routing table starting at
208.197.169.0:user@host>show route | find 208.197.169.0208.197.169.0/24 *[Static/5] 1d 13:22:11> to 192.168.4.254 via so-3/0/0.0224.0.0.5/32 *[OSPF/10] 1d 13:22:12, metric 1iso.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both47.0005.80ff.f800.0000.0108.0001.1921.6800.4015.00/160*[Direct/0] 1d 13:22:12> via lo0.0