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


Filter Command Output

For operational and configuration commands that display output, such as the show commands, you can filter the output. When you display help about these commands, one of the options listed is |, called a pipe, which allows you to filter the command output. For example:

user@host> show configuration ?
Possible completions:
    <[Enter]>                Execute this command
    |                Pipe through a command
user@host> show configuration | ? 
Possible completions:
    count                Count occurrences
    except                Show only text that does not match a pattern
    find                Search for the first occurrence of a pattern
    hold                Hold text without exiting the ----More--- prompt
    last                Show the specified number of lines from the end of the output
    match                Show only text that matches a pattern
    no-more                Don't paginate output
    resolve                Resolve IP addresses
    save                Save output text to a file
    trim                Trim specified number of columns from the start line

In configuration mode, two additional filters appear, display and compare:

[edit]
user@host # show | ? 
Possible completions:
    compare                Compare configuration changes with a prior version
    count                Count occurrences
    display                Display additional configuration information
    except                Show only text that does not match a pattern
    find                Search for the first occurrence of a pattern
    hold                Hold text without exiting the ----More--- prompt
    last                Show specified number of lines from the end of the ouput
    match                Show only text that matches a pattern
    no-more                Don't paginate output
    resolve                Resolve IP addresses
    save                Save output text to a file
    trim                Trim specified number of columns from the start line

The following filtering operations are available:

Place Command Output in a File

When the output is very long, when you need to store or analyze the output, or when you need to email or FTP the output, you can place the output of a command into a file. Doing this is useful when the output scrolls off the screen, making it difficult to cut the output from a window and paste it into another.

To save the output to a file, specify the save command after the pipe:

user@host> command | save filename 

By default, the file is placed in your home directory on the router. For information about how you can specify the name of the file, see Specify Filenames and URLs.

This example stores the output of the request support information command in a file:

user@host> request support information | save filename 
Wrote 1143 lines of output to `filename'
user@host>

Search 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 6 lists common regular expression operators.


Table 6: Common Regular Expression Operators

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 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 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 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 into 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

Compare Configuration Changes with a Prior Version

In configuration mode only, when you have made changes to the configuration and want to compare the candidate configuration with a prior version, you can use the compare command to display the configuration. The compare command compares the candidate configuration with either the current committed configuration or a configuration file and displays the differences between the two configurations. To compare configurations, specify the compare command after the pipe:

[edit]
user@host# show | compare [filename | rollback n]

filename is the full path to a configuration file. The file must be in the proper format: a hierarchy of statements. For information about how to save a configuration to a file, see Save a Configuration to a File. For information about formatting the hierarchy of statements, see Configuration Statement Hierarchy.

n is the index into the list of previously committed configurations. The most recently saved configuration is number 0, and the oldest saved configuration is number 9. If you do not specify arguments, the candidate configuration is compared against the active configuration file (/config/juniper.conf).

The comparison output uses the following conventions:

The following example shows various changes, then a comparison of the candidate configuration with the active configuration, showing only the changes made at the [edit protocols bgp] hierarchy level.

[edit]
user@host# edit protocols bgp 

[edit protocols bgp]
user@host# show 
group my-group {
    type internal;
    hold-time 60;
    advertise-inactive;
    allow 1.1.1.1/32;
}
group fred {
    type external;        
    peer-as 33333;    
    allow 2.2.2.2/32;
}
group test-peers {
    type external;
    allow 3.3.3.3/32;
}
[edit protocols bgp]
user@host# set group my-group hold-time 90 
[edit protocols bgp]
user@host# delete group my-group advertise-inactive 
[edit protocols bgp]
user@host# set group fred advertise-inactive 
[edit protocols bgp]
user@host# delete group test-peers 
[edit protocols bgp]
user@host# show | compare 
[edit protocols bgp group my-group]
-    hold-time 60;
+    hold-time 90;
-    advertise-inactive;
[edit protocols bgp group fred]
+    advertise-inactive;
[edit protocols bgp]
-group test-peers {
-    type external;
-    allow 3.3.3.3/32;
-}
[edit protocols bgp]
user@host# show 
group my-group {
    type internal;
    hold-time 90;
    allow 1.1.1.1/32;
}
group fred {
    type external;
    advertise-inactive;
    peer-as 3333;
    allow 2.2.2.2/32;
}

Count the Number of Lines in the Output

To count the number of lines in the output, specify the count command after the pipe:

user@host> command | count 

For example:

user@host> show configuration | count
Count: 269 lines
user@host> show route | count
Count: 67 lines

Display All Output at Once

To display the output all at once instead of one screen at a time, specify the no-more command after the pipe. This command is equivalent to the set cli screen-length 0 command, but affects the output of the one command only.

user@host> command | no-more 


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