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


Filtering Operational Mode Command Output

You can redirect the output of operational mode commands into a file or into filters. When you display help about these commands, one of the options listed is | , which is a pipe filter. 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
  display              Show additional kinds of information
  except               Show only text that does not match a pattern
  find                 Search for first occurrence of pattern
  hold                 Hold text without exiting the --More-- prompt
  last                 Display end of output only
  match                Show only text that matches a pattern
  no-more              Don't paginate output
  request              Make system-level requests
  resolve              Resolve IP addresses
  save                 Save output text to file
  trim                 Trim specified number of columns from start of line

Table 7 describes the commands that can be used with the pipe ( | ) option in operational mode.


Table 7: Filtering Operational Mode Command Output
Filter Keyword
Description
See Also

count

Displays the number of lines in the output.

Counting the Number of Lines in the Output

display xml

Displays the XML content of the command.


except pattern

Ignores text matching the regular expression. If the regular expression contains spaces, operators, or wildcard characters, enclose it in quotation marks (" " ).

Searching for a String in the Output

find pattern

Displays output starting at the first occurrence of text matching the regular expression. If the regular expression contains spaces, operators, or wildcard characters, enclose it in quotation marks (" " ).

Searching for a String in the Output

hold

Holds text without exiting the -More- prompt.

Retaining the Output After the Last Screen

last lines

Displays text starting at the specified number of lines from the end of the output.

Displaying the Lines You Want to View from the End of the Output

match pattern

Searches for text matching the regular expression. If the regular expression contains spaces, operators, or wildcard characters, enclose it in quotation marks.

Searching for a String in the Output

no-more

Displays output all at once rather than one screen at a time.

Displaying All Output at Once

request message (all | user account@terminal)

Display command output on the terminal of a specific user logged onto your router, or on the terminals of all users logged onto your router.

Sending Command Output to Other Users

resolve [full-names | truncate]

Converts IP addresses into domain name server (DNS) names. By default, names are truncated to fit the original size. To prevent names from being truncated, use the full-names keyword.


save filename

Saves the output to a file.

Placing Command Output in a File

trim columns

Trims the specified number of columns from the start line.




NOTE: Additional options are available in configuration mode. For these options, see the JUNOS System Basics Configuration Guide.

For the output of a single command, you can redirect the output one or more times. For example:

user@host> command | match regular-expression | except regular-expression | 
match other-regular-expression | find regular-expression | hold

The following sections provide additional information for most of the pipe ( | ) filter options described in Table 7:

Counting the Number of Lines in the Output

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

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

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 except command after the pipe:

user@host> command | except regular-expression 

To find the first occurrence of a regular expression, specify the find command after the pipe:

user@host> command | find regular-expression 

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

user@host> command | match 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
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 and 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 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 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

Retaining the Output After the Last Screen

When you view output one screen at a time, you typically return to the CLI prompt after viewing the last screen.

To not return immediately, use the hold command after the pipe. This feature is useful, for example, when you want to scroll or search through the output.

user@host> command | hold 

Displaying the Lines You Want to View from the End of the Output

By default, the last command displays the lines from the end of the output. You can also specify the number of lines to display from the end of the output. If the number of specified lines is less than a screen full, the command will display a screen full of output. This feature is most useful for viewing log files where the end of the files contain the most recent entries.

To view the most recent entries from the end of the output, use the | last command after the pipe:

user@host> show command | last lines

lines specifies the number of lines to display from the end of output.

Displaying 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 

Sending Command Output to Other Users

If you are troubleshooting your router and, for example, talking with a customer service representative on the phone, you can use the request message command to send your representative the command output you are currently viewing on your terminal.

The following example sends the output from the show interfaces command you enter on your terminal to the terminal of the user root@ttyp1:

root@ui6% who
root     ttyp0 Nov  3 12:42     (172.17.28.75)
root     ttyp1 Nov 30 10:32     (172.17.28.75)
root@ui6% cli
root@ui6> show interfaces | request message user root@ttyp1

The user root@ttyp1 sees the following output appear on his terminal screen:

Message from root@ui6 on /dev/ttyp0 at 10:32 PST...
Physical interface: dsc, Enabled, Physical link is Up
   Interface index: 5, SNMP ifIndex: 5
   Type: Software-Pseudo, MTU: Unlimited ...

Placing 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 send the output in e-mail, you can redirect the output to 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 filename, see Specifying 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>

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