Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Filtering Operational Command Output

 

The pipe | symbol lets you filter the command output in both operational and configuration modes. For more information on the pipe | filter functions, see the following topics:

Using the Pipe ( | ) Symbol to Filter Junos OS Command Output

The Junos OS enables you to filter command output by adding the pipe ( | ) symbol when you enter a command.

For example:

user@host> show rip neighbor ?

The following example lists the filters that can be used with the pipe symbol ( | ):

user@host> show interfaces | ?

For the show configuration command only, an additional compare filter is available:

user@host> show configuration | ?

You can enter any of the pipe filters in conjunction. For example:

Note

This topic describes only the filters that can be used for operational mode command output. For information about filters that can be used in configuration mode, see the Junos OS Administration Library.

Using Regular Expressions with the Pipe ( | ) Symbol to Filter Junos OS Command Output

The except, find, and match filters used with the pipe symbol employ regular expressions to filter output. Juniper Networks uses the regular expressions as defined in POSIX 1003.2. If the regular expressions contain spaces, operators, or wildcard characters, enclose the expression in quotation marks.

Table 1: Common Regular Expression Operators in Operational Mode Commands

Operator

Function

|

Indicates that a match can be one of the two terms on either side of the pipe.

^

Used at the beginning of an expression, denotes where a match should begin.

$

Used at the end of an expression, denotes that a term must be matched exactly up to the point of the $ character.

[ ]

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

( )

Specifies a group of terms to match.

For example, if a command produces the following output:

a pipe filter of | match "FPC 1" displays the following output:

and a pipe filter of | except "FPC 1" displays the following output:

Pipe ( | ) Filter Functions in the Junos OS Command-Line Interface

This topic describes the pipe ( | ) filter functions that are supported in the Junos OS command-line interface (CLI):

Comparing Configurations and Displaying the Differences in Text

The compare filter compares the candidate configuration with either the current committed configuration or a configuration file and displays the differences between the two configurations with text characters. To compare configurations, enter compare after the pipe ( | ) symbol:

filename is the full path to a configuration file.

n is the index into the list of previously committed configurations. The most recently saved configuration is 0. 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:

  • Statements that are only in the candidate configuration are prefixed with a plus sign (+).

  • Statements that are only in the comparison file are prefixed with a minus sign (–).

  • Statements that are unchanged are prefixed with a single blank space ( ).

For example:

user@host> show configuration system | compare rollback 9

Starting with Junos OS Release 8.3, output from the show | compare command has been enhanced to more accurately reflect configuration changes. This includes more intelligent handling of order changes in lists. For example, consider names in a group that are reordered as follows:

In previous releases, output from the show | compare command looked like the following:

Now, output from the show | compare command looks like the following:

Comparing Configurations and Displaying the Differences in XML

The compare | display xml filter compares the candidate configuration with the current committed configuration and displays the differences between the two configurations in XML. To compare configurations, enter compare | display xml after the pipe ( | ) symbol in either operational or configuration mode.

Example in operational mode:

Example in configuration mode:

You can enter a specific configuration hierarchy prior to | compare. In configuration mode, you can navigate to a hierarchy where the command is applied.

For a description of the XML output, see Understanding the show | compare | display xml Command Output.

Note

Starting in Junos OS Release 16.2R2, the show | compare | display xml command omits the <configuration> tag in the XML output if the comparison returns no differences or if the comparison returns only differences for non-native configuration data, for example, configuration data associated with an OpenConfig data model.

Counting the Number of Lines of Output

To count the number of lines in the output from a command, enter count after the pipe symbol ( | ). For example:

user@host> show configuration | count

Displaying Output in XML Tag Format

To display command output in XML tag format, enter display xml after the pipe symbol ( | ).

The following example displays the show cli directory command output as XML tags:

user@host> show cli directory | display xml

If the configuration data or command output contains characters that are outside of the 7-bit ASCII character set, the Junos OS CLI displays the equivalent UTF-8 decimal character reference for those characters in the XML output. For more information, see Understanding Character Encoding on Devices Running Junos OS

To display the change in the candidate and active configurations in XML tag format, see Comparing Configurations and Displaying the Differences in XML.

Displaying Static Configuration Data

To view the inherited configuration data and information about the source group from which the configuration has been inherited with respect to the static configuration database, issue the show configuration | display inheritance command.

user@host> show configuration | display inheritance

Displaying Ephemeral Configuration Data

Juniper Extension Toolkit (JET) applications and NETCONF and Junos XML protocol client applications can configure the ephemeral configuration database. The ephemeral database is an alternate configuration database that provides a fast programmatic interface for performing configuration updates.

In Junos OS Release 18.1 and earlier, to view the complete post-inheritance configuration merged with the configuration data in all instances of the ephemeral configuration database, issue the show ephemeral-configuration | display merge command.

user@host> show ephemeral-configuration | display merge
Note

Starting in Junos OS Release 18.2R1, the display merge option is deprecated. To view the complete post-inheritance configuration merged with the configuration data in all instances of the ephemeral database, issue the show ephemeral-configuration merge command.

Displaying Output in JSON Format

Starting in Junos OS Release 14.2, you can display the configuration or command output in JavaScript Object Notation (JSON) format by entering display json after the pipe symbol ( | ).

The following example displays the show cli directory command output in JSON format:

user@host> show cli directory | display json

If the operational command output contains characters that are outside of the 7-bit ASCII character set, the Junos OS CLI displays the equivalent UTF-8 decimal character reference for those characters in the JSON output. For more information, see Understanding Character Encoding on Devices Running Junos OS

Note

Starting in Junos OS Release 16.1, devices running Junos OS emit JSON-formatted configuration data using a new default implementation for serialization.

Note

Starting in Junos OS Releases 16.1R4, 16.2R2, and 17.1R1, integers in Junos OS configuration data emitted in JSON format are not enclosed in quotation marks. In earlier releases, integers in JSON configuration data were treated as strings and enclosed in quotation marks.

Note

Starting in Junos OS Release 17.3R1, OpenConfig supports the operational state emitted by daemons directly in JSON format in addition to XML format. To configure JSON compact format, specify the following CLI command:

set system export-format state-data json compact.

This CLI command converts XML format to compact JSON format. Else, it emits the JSON in non-compact format.

Displaying the Configuration with YANG Translation Scripts Applied

Starting in Junos OS Release 16.1, you can load YANG modules onto devices running Junos OS to augment the configuration hierarchy with data models that are not natively supported by Junos OS but can be supported by translation. The active and candidate configurations contain the configuration data for non-native YANG data models in the syntax defined by that model, but they do not explicitly display the corresponding translated Junos OS syntax, which is committed as a transient change.

The | display translation-scripts filter displays the complete post-inheritance configuration, with the translated configuration data from all enabled translation scripts explicitly included in the output. To display the configuration with all enabled YANG translation scripts applied, append the | display translation-scripts filter to the show configuration command in operational mode or the show command in configuration mode. For example:

user@host> show configuration | display translation-scripts

To view just the non-native configuration data after translation, use the | display translation-scripts translated-config filter in either operational or configuration mode.

user@host> show configuration | display translation-scripts translated-config

In configuration mode, to display just the configuration differences in the hierarchies corresponding to non-native YANG data models before or after translation scripts are applied, append the configured-delta or translated-delta keyword, respectively, to the show | display translation-scripts command. In both cases, the XML output displays the deleted configuration data, followed by the new configuration data.

user@host# show | display-translation-scripts (configured-delta | translated-delta)

The following example displays a sample configuration with and without translation scripts applied. The show command displays the configuration, which includes the non-native configuration data in the syntax defined by the YANG data model. The | display translation-scripts filter displays the non-native configuration data in both the syntax defined by the YANG data model and the translated Junos OS syntax. Both commands display the entire configuration, which has been truncated for brevity in this example. However, the show command returns the pre-inhertitance configuration, whereas the show | display translation-scripts command returns the post-inheritance configuration.

user@host# show
user@host# show | display translation-scripts

Displaying the RPC Tags for a Command

To display the remote procedure call (RPC) XML tags for an operational mode command, enter display xml rpc after the pipe symbol ( | ).

The following example displays the RPC tags for the show route command:

user@host> show route | display xml rpc

Ignoring Output That Does Not Match a Regular Expression

To ignore text that matches a regular expression, specify the except command after the pipe symbol ( | ). If the regular expression contains any spaces, operators, or wildcard characters, enclose it in quotation marks. For information on common regular expression operators, see Using Regular Expressions with the Pipe ( | ) Symbol to Filter Junos OS Command Output.

The following example displays all users who are logged in to the router, except for the user root:

user@host> show system users | except root

Displaying Output from the First Match of a Regular Expression

To display output starting with the first occurrence of text matching a regular expression, enter find after the pipe symbol ( | ). If the regular expression contains any spaces, operators, or wildcard characters, enclose it in quotation marks. For information on common regular expression operators, see Using Regular Expressions with the Pipe ( | ) Symbol to Filter Junos OS Command Output.

The following example displays the routes in the routing table starting at IP address 208.197.169.0:

user@host> show route | find 208.197.169.0

The following example displays the first CCC entry in the forwarding table:

user@host> show route forwarding-table | find ccc

Retaining Output After the Last Screen

To not return immediately to the CLI prompt after viewing the last screen of output, enter hold after the pipe symbol ( | ). The following example prevents returning to the CLI prompt after you have viewed the last screen of output from the show log log-file-1 command:

user@host> show log log-file-1 | hold

This filter is useful when you want to scroll or search through output.

Displaying Output Beginning with the Last Entries

To display text starting from the end of the output, enter last <lines> after the pipe symbol ( | ).

The following example displays the last entries in log-file-1 file:

user@host> show log log-file-1 | last

This filter is useful for viewing log files in which the end of the file contains the most recent entries.

Note

When the number of lines requested is less than the number of lines that the screen length setting permits you to display, Junos OS returns as many lines as permitted by the screen length setting. That is, if your screen length is set to 20 lines and you have requested only the last 10 lines, Junos OS returns the last 19 lines instead of the last 10 lines.

Displaying Output That Matches a Regular Expression

To display output that matches a regular expression, enter match regular-expression after the pipe symbol ( | ). If the regular expression contains any spaces, operators, or wildcard characters, enclose it in quotation marks. For information on common regular expression operators, see Using Regular Expressions with the Pipe ( | ) Symbol to Filter Junos OS Command Output.

The following example matches all the Asynchronous Transfer Mode (ATM) interfaces in the configuration:

user@host> show configuration | match at-

Preventing Output from Being Paginated

By default, if output is longer than the length of the terminal screen, you are provided with a ---(more)--- message to display the remaining output. To display the remaining output, press the Spacebar.

To prevent the output from being paginated, enter no-more after the pipe symbol ( | ).

The following example displays output from the show configuration command all at once:

This feature is useful, for example, if you want to copy the entire output and paste it into an e-mail.

Sending Command Output to Other Users

To display command output on the terminal of a specific user logged in to your router, or on the terminals of all users logged in to your router, enter request message (all | user account@terminal) after the pipe symbol ( | ).

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:

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

Resolving IP Addresses

In operational mode only, if the output of a command displays an unresolved IP address, you can enter | resolve after the command to display the name associated with the IP address. The resolve filter enables the system to perform a reverse DNS lookup of the IP address. If DNS is not enabled, the lookup fails and no substitution is performed.

To perform a reverse DNS lookup of an unresolved IP address, enter resolve <full-names> after the pipe symbol ( | ). If you do not specify the full-names option, the name is truncated to fit whatever field width limitations apply to the IP address.

The following example performs a DNS lookup on any unresolved IP addresses in the output from the show ospf neighbors command:

Saving Output to a File

When command output is lengthy, when you need to store or analyze the output, or when you need to send the output in an e-mail or by FTP, you can save the output to a file. By default, the file is placed in your home directory on the router.

To save command output to a file, enter save filename after the pipe symbol ( | ).

The following example saves the output from the request support information command to a file named my-support-info.txt:

Appending Output to a File

When command output is displayed, you can either save the output to a file, which overwrites the existing contents of that file or you can append the output text to a specific file.

To append the command output to the file, enter append filename after the pipe symbol ( | ).

The following example appends the output from the request support information command to a file named my-support-info.txt:

Displaying Output on Screen and Writing to a File

When command output is displayed, you can also write the output to a file. To both display the output and write it to a file, enter tee filename after the pipe symbol (|).

The following example displays the output from the show interfaces ge-* terse command (displaying information about the status of the Gigabit Ethernet interfaces on the device) and diverts the output to a file called ge-interfaces.txt:

user@host> show interfaces ge-* terse | tee ge-interfaces.txt

Unlike the UNIX tee command, only an error message is displayed if the file cannot be opened (instead of displaying the output and then the error message).

user@host> show interfaces ge-* terse | tee /home/user/test.txt

Trimming Output by Specifying the Starting Column

Output appears on the terminal screen in terms of rows and columns. The first alphanumeric character starting at the left of the screen is in column 1, the second character is in column 2, and so on. To display output starting from a specific column (thus trimming the leftmost portion of the output), enter trim columns after the pipe symbol ( | ). The trim filter is useful for trimming the date and time from the beginning of system log messages.

The following example displays output from the show system storage command, filtering out the first 10 columns:

Note

The trim command does not accept negative values.

Refreshing the Output of a Command

You can run an operational mode command with the | refresh pipe option to refresh the output displayed on the screen periodically. The default refresh occurs every second. However, you can also explicitly specify a refresh interval from 1 through 604,800 seconds. For example, to refresh the output of the show interfaces command every 5 seconds, you would run the following command:

user@host> show interfaces | refresh 5

Filtering Operational Mode Command Output in a QFabric System

When you issue an operational mode command in a QFabric system, the output generated can be fairly extensive because of the number of components contained within the system. To make the output more accessible, you can filter the output by appending the | filter option to the end of most Junos OS commands.

  1. To filter operational mode command output and limit it to a Node group, include the | filter node-group node-group-name option at the end of your Junos OS operational mode command.
    root@qfabric> show interfaces terse | filter node-group NW-NG-0
  2. To filter operational mode command output and limit it to a set of Node groups, include the | filter node-group option at the end of your Junos OS operational mode command and specify the list of Node group names in brackets.
    root@qfabric> show ethernet-switching interfaces | filter node-group [NW-NG-0 RSNG-1]
Release History Table
Release
Description
Starting in Junos OS Release 18.2R1, the display merge option is deprecated. To view the complete post-inheritance configuration merged with the configuration data in all instances of the ephemeral database, issue the show ephemeral-configuration merge command.
Starting in Junos OS Release 17.3R1, OpenConfig supports the operational state emitted by daemons directly in JSON format in addition to XML format. To configure JSON compact format, specify the following CLI command:

set system export-format state-data json compact.

This CLI command converts XML format to compact JSON format. Else, it emits the JSON in non-compact format.
Starting in Junos OS Release 16.2R2, the show | compare | display xml command omits the <configuration> tag in the XML output if the comparison returns no differences or if the comparison returns only differences for non-native configuration data, for example, configuration data associated with an OpenConfig data model.
Starting in Junos OS Releases 16.1R4, 16.2R2, and 17.1R1, integers in Junos OS configuration data emitted in JSON format are not enclosed in quotation marks. In earlier releases, integers in JSON configuration data were treated as strings and enclosed in quotation marks.
Starting in Junos OS Release 16.1, devices running Junos OS emit JSON-formatted configuration data using a new default implementation for serialization.
Starting in Junos OS Release 16.1, you can load YANG modules onto devices running Junos OS to augment the configuration hierarchy with data models that are not natively supported by Junos OS but can be supported by translation.
Starting in Junos OS Release 14.2, you can display the configuration or command output in JavaScript Object Notation (JSON) format by entering display json after the pipe symbol ( | ).