Filter Command Output
For operational and configuration commands that display output, such as the
showcommands, 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 commanduser@host> show configuration| ?Possible completions:count Count occurrencesexcept Show only text that does not match a patternfind Search for the first occurrence of a patternhold Hold text without exiting the ----More--- promptlast Show the specified number of lines from the end of the outputmatch Show only text that matches a patternno-more Don't paginate outputresolve Resolve IP addressessave Save output text to a filetrim Trim specified number of columns from the start lineIn configuration mode, two additional filters appear,
displayandcompare:[edit]user@host #show | ?Possible completions:compare Compare configuration changes with a prior versioncount Count occurrencesdisplay Display additional configuration informationexcept Show only text that does not match a patternfind Search for the first occurrence of a patternhold Hold text without exiting the ----More--- promptlast Show specified number of lines from the end of the ouputmatch Show only text that matches a patternno-more Don't paginate outputresolve Resolve IP addressessave Save output text to a filetrim Trim specified number of columns from the start lineThe following filtering operations are available:
- Place Command Output in a File
- Search for a String in the Output
- Compare Configuration Changes with a Prior Version
- Count the Number of Lines in the Output
- Display All Output at Once
- Display the Lines You Want to View from the End of the Output
- Retain the Output after the Last Screen
- Display Additional Information about the Configuration
- Filter Command Output Multiple Times
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
savecommand after the pipe:user@host>command| savefilenameBy 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 informationcommand in a file:user@host>request support information | savefilenameWrote 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
matchcommand after the pipe:user@host>command|matchregular-expressionTo ignore text that matches a regular expression, specify the
exceptcommand after the pipe:user@host>command|exceptregular-expressionIf the
regular-expressioncontains 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.
For example, if a command produces the following output:
one twotwo twothree two onefourThe
match twocommand displays:one twotwo twothree two oneThe
except onecommand displays:two twofourList 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 root8:28PM up 1 day, 13:59, 2 users, load averages: 0.01, 0.01, 0.00USER TTY FROM LOGIN@ IDLE WHATsheep p0 baa.juniper.net 7:25PM - cliSave the configuration, except for encrypted passwords, to a file:
user@host>show configuration | except SECRET-DATA | save my.output.fileDisplay the output, starting not at the beginning but rather at the first occurrence of text matching a regular expression, using the
findcommand after the pipe:user@host>command|findregular-expressionIf 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.0208.197.169.0/24 *[Static/5] 1d 13:22:11> to 192.168.4.254 via so-3/0/0.0224.0.0.5/32 *[OSPF/10] 1d 13:22:12, metric 1iso.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)+ = Active Route, - = Last Active, * = Both47.0005.80ff.f800.0000.0108.0001.1921.6800.4015.00/160*[Direct/0] 1d 13:22:12> via lo0.0Compare 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
comparecommand to display the configuration. Thecomparecommand 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 thecomparecommand after the pipe:[edit]user@host#show | compare[filename|rollbackn]
filenameis 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.
nis 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:
- 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 ( ).
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#showgroup 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#showgroup 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
countcommand after the pipe:user@host>command|countuser@host>show configuration | countCount: 269 linesuser@host>show route | countCount: 67 linesDisplay All Output at Once
To display the output all at once instead of one screen at a time, specify the
no-morecommand after the pipe. This command is equivalent to theset cli screen-length 0command, but affects the output of the one command only.user@host>command|no-more