Supported Platforms
Related Documentation
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
- Counting the Number of Lines of Output
- Displaying Output in XML Tag Format
- Displaying the RPC tags for a Command
- Ignoring Output That Does Not Match a Regular Expression
- Displaying Output from the First Match of a Regular Expression
- Retaining Output After the Last Screen
- Displaying Output Beginning with the Last Entries
- Displaying Output That Matches a Regular Expression
- Preventing Output from Being Paginated
- Sending Command Output to Other Users
- Resolving IP Addresses
- Saving Output to a File
- Trimming Output by Specifying the Starting Column
Comparing Configurations
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. 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
[edit system] + host-name hostrouter; + backup-router 192.168.71.254; - ports { - console log-out-on-disconnect; - } [edit system name-server] + 172.17.28.11; 172.17.28.101 { ... } [edit system name-server] 172.17.28.101 { ... } + 172.17.28.100; + 172.17.28.10; [edit system] - scripts { - commit { - allow-transients; - } - } + services { + ftp; + rlogin; + rsh; + telnet; + }
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:
groups { groups { group_xmp; group_xmp; group_cmp; group_grp: group_grp; group_cmp; } }
In previous releases, output from the show | compare command looked like the following:
[edit groups] - group_xmp; - group_cmp; - group_grp; + group_xmp; + group_grp; + group_cmp;
Now, output from the show | compare command looks like the following:
[edit groups] group_xmp {...} ! group_grp {...}
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
Count: 269 lines
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
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/7.5I0/junos"> <cli> <working-directory>/var/tmp/<working-directory> </cli> <cli> <banner></banner> </cli> </rpc-reply>
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
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.1I0/junos"> <rpc> <get-route-information> </get-route-information> </rpc> <cli> <banner></banner> </cli> </rpc-reply>
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 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
8:28PM up 1 day, 13:59, 2 users, load averages: 0.01, 0.01, 0.00 USER TTY FROM LOGIN@ IDLE WHAT user p0 device1.example.com 7:25PM - cli
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 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
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
The following example displays the first CCC entry in the forwarding table:
user@host> show route forwarding-table | find
ccc
Routing table: ccc MPLS: Interface.Label Type RtRef Nexthop Type Index NhRef Netif default perm 0 rjct 3 1 0 user 0 recv 5 2 1 user 0 recv 5 2 32769 user 0 ucst 45 1 fe-0/0/0.534 fe-0/0/0. (CCC) user 0 indr 44 2 10.0.16.2 Push 32768, Push
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 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 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 Command Output.
The following example matches 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 {
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:
Message from user@host 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...
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:
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: