[Contents] [Prev] [Next] [Index] [Report an Error]


Searching for a String in the Output

You can search for text matching a regular expression by filtering output. You can make a regular expression match everything except a regular expression, or find the first occurrence of text matching a regular expression. Searches are not case-sensitive.

To match a regular expression, specify the match command after the pipe:

user@host> command | match regular-expression 

To ignore text that matches a regular expression, specify the except command after the pipe:

user@host> command | except regular-expression 

If the regular-expression contains 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 8 lists common regular expression operators.


Table 8: Common Regular Expression Operators in Operational Mode Commands
Operator
Match...

|

One of the two terms on either side of the pipe.

^

At the beginning of an expression, used to denote where the command begins, where there might be some ambiguity.

$

Character at the end of a command. Used to denote a command that must be matched exactly up to that point. For example, allow-commands "show interfaces$" means that the user can issue the show interfaces command but cannot issue show interfaces detail or show interfaces extensive.

[ ]

Range of letters or digits. To separate the start and end of a range, use a hyphen ( - ).

( )

A group of commands, indicating an expression to be evaluated; the result is then evaluated as part of the overall expression.


For example, if a command produces the following output:

one two
two two
three two one
four

The match two command displays:

one two
two two
three two one

The except one command displays:

two two
four

List all the Asynchronous Transfer Mode (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 super-user {
        user juniper {
            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 root
 8:28PM  up 1 day, 13:59, 2 users, load averages: 0.01, 0.01, 0.00
USER     TTY FROM              LOGIN@  IDLE WHAT
sheep    p0  baa.juniper.net   7:25PM     - cli

Save the configuration, except for encrypted passwords, to a file:

user@host> show configuration | except SECRET-DATA | save my.output.file 

Display the output, starting not at the beginning but rather at the first occurrence of text matching a regular expression, using the find command after the pipe:

user@host> command | find regular-expression 

If 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.0
208.197.169.0/24   *[Static/5] 1d 13:22:11
                    > to 192.168.4.254 via so-3/0/0.0
224.0.0.5/32       *[OSPF/10] 1d 13:22:12, metric 1

iso.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

47.0005.80ff.f800.0000.0108.0001.1921.6800.4015.00/160
                   *[Direct/0] 1d 13:22:12
                    > via lo0.0

[Contents] [Prev] [Next] [Index] [Report an Error]