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 (the network administrator) filter the command output in both operational and configuration modes.

About Using the Pipe ( | ) Symbol to Filter Command Output

You can filter command output by adding the pipe ( | ) symbol when you enter the command.

Example:

The following example lists the filters that you can use with the pipe symbol ( | ):

For the show configuration command only, you can combine the pipe symbol and question mark to display an additional compare filter:

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

Note:

This topic describes only the filters that you can use for operational mode command output.

Example: Use Regular Expressions with the Pipe ( | ) Symbol to Filter Command Output

You use the except, find, and match filters with the pipe symbol to employ regular expressions to filter output. Juniper Networks uses the regular expressions as defined in POSIX 1003.2. If a regular expression contains 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 to denote where a match should begin.

$

Used at the end of an expression to denote 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:

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

Example: Pipe ( | ) Filter Functions in the Command-Line Interface

This topic describes and provides examples of the pipe ( | ) filter functions that the Junos OS CLI supports.

Examples of Configurations and Their Differences in Text

The compare filter compares the candidate configuration with either the current committed configuration or a configuration file. It also displays the differences between the two configurations with text characters.

To compare configuration files, you enter compare after the pipe ( | ) symbol, as follows:

The rollback n variable 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), which is the same as comparing to rollback index 0.

The full path (or URL) to a configuration file is filename.

The comparison output uses the following conventions:

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

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

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

Example:

We have enhanced output from the show | compare command to more accurately reflect configuration changes. This enhancement includes more intelligent handling of order changes in lists. For example, consider group names that are reordered as follows:

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

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

Examples of Configurations and Their 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, you 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 before using the | compare command. In configuration mode, you can navigate to a hierarchy where the command is applied.

Example of Counting the Number of Lines of Output

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

Example of Output Displayed in XML Tag Format

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

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

If the configuration data or command output contains characters that are outside of the 7-bit ASCII character set, the CLI displays the equivalent UTF-8 decimal character reference for those characters in the XML output.

Example of Displaying Static Configuration Data

You can 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. To view this data, you issue the show configuration | display inheritance command.

Example of Displaying Ephemeral Configuration Data

Juniper Extension Toolkit (JET) applications, Network Configuration Protocol (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.

To view the complete post-inheritance configuration merged with the configuration data in all instances of the ephemeral database, use the show ephemeral-configuration merge command.

Example of Displaying Output in JSON Format

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:

If the operational command output contains characters that are outside of the 7-bit ASCII character set, the CLI displays the equivalent UTF-8 decimal character reference for those characters in the JSON output.

Example of Displaying the Configuration with YANG Translation Scripts Applied

You can load YANG modules onto devices running Junos OS to augment the configuration hierarchy with data models that Junos OS does not support natively. Junos OS does support translation of these models.. The active configurations and candidate configurations contain the configuration data for non-native YANG data models in the syntax defined by that model. These configurations 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:

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

In configuration mode, you can display just the configuration differences in the hierarchies corresponding to non-native YANG data models before or after translation scripts are applied. To display those differences, you 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.

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 that the YANG data model defines. 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.

Example of Displaying the RPC Tags for a Command

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

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

Example of 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.

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

Example of Displaying Output from the First Match of a Regular Expression

To display output starting with the first occurrence of text matching a regular expression, you enter find after the pipe symbol ( | ). If the regular expression contains any spaces, operators, or wildcard characters, enclose it in quotation marks.

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

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

Example of Retaining Output After the Last Screen

You can retain output and scroll or search through it by holding rather than returning immediately to the CLI prompt after viewing the last screen of output. To retain output, you 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:

Example of Displaying Output Beginning with the Last Entries

You can view log files in which the end of the file contains the most recent entries. To display text starting from the end of the output, you enter last <lines> after the pipe symbol ( | ).

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

Note:

When the number of lines requested is less than the number of lines that the screen length setting permits you to display, the system returns a subset. The system 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, the system returns the last 19 lines instead of the last 10 lines.

Example of Displaying Output That Matches a Regular Expression

To display output that matches a regular expression, you enter match regular-expression after the pipe symbol ( | ). If the regular expression contains any spaces, operators, or wildcard characters, enclose it in quotation marks.

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

Example of Preventing Output from Being Paginated

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

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

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

This feature is useful if you want to copy the entire output and paste it into an email message.

Example of 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, you enter request message (all | user account@terminal) after the pipe symbol ( | ).

If you are troubleshooting your router and talking with a customer service representative on the phone, you can share the command output. You 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 that 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:

Example of 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, you 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:

Example of 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 message 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, you 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:

Example of 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, you 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:

Example of 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, you 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:

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).

Example of 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), you 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.

Example of 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 run the following command:

Filter 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 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 operational mode command. For example:
  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 operational mode command and specify the list of Node group names in brackets. For example:

Change History Table

Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.

Release
Description
18.2R1
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, use the show ephemeral-configuration | display merge command. Starting in Junos OS Release 18.2R1, the display merge option is deprecated.
17.3R1
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, use the command set system export-format state-data json compact. This command converts XML format to compact JSON format. Else, it emits the JSON in non-compact format.
16.2R2
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.
16.2R2
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.
16.1
Starting in Junos OS Release 16.1, devices running Junos OS emit JSON-formatted configuration data using a new default implementation for serialization.
16.1
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.
14.2
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 ( | ).
8.3
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.