Using the Pipe '|' command

Using the Pipe '|' command

When working with the Cisco command line interface (CLI), it is very common to see long outputs. When looking at items like the running configuration or the routing table, you will often find that the output spans many pages. This makes it difficult to read and find the information you need.

Cisco IOS provides the use of the pipe | command which allows you to filter CLI output. By using the pipe command you can display only the lines you're interested in, instead of having to scroll through potentially hundreds of lines to find what you need.

Let's take a look at the various options available with the pipe command and how they can make your life easier when working with the Cisco CLI.

Pipe Command Options

The pipe command has three main options:

  • include - shows only lines that contain the specified text
  • exclude - shows only lines that do NOT contain the specified text
  • begin - shows all lines starting from the first line that contains the specified text

Using the Include Option

The include option is probably the most commonly used pipe command. It allows you to display only the lines that contain specific text. For example, if you want to see only the interface configurations in your running config, you could use:

Router# show running-config | include interface

This would display only the lines containing the word "interface".

Using the Exclude Option

The exclude option does the opposite of include - it shows you everything EXCEPT the lines containing the specified text. This can be useful when you want to filter out certain information. For example:

Router# show ip interface brief | exclude down

This would show you all interfaces except those that are down.

Using the Begin Option

The begin option starts displaying output from the first line that matches your criteria and continues to the end of the output. This is particularly useful when you want to see a specific section of a long configuration. For example:

Router# show running-config | begin router ospf

This would start displaying the configuration from the OSPF router configuration section and continue to the end of the running config.

Combining Multiple Pipes

You can also chain multiple pipe commands together to create more complex filters. For example:

Router# show running-config | include interface | exclude Loopback

This would show only lines containing "interface" but exclude any lines containing "Loopback".

Case Sensitivity

It's important to note that the pipe command is case-sensitive. This means that | include Interface and | include interface will give you different results. Make sure to match the exact case used in the output.

Regular Expressions

The pipe command also supports basic regular expressions, which allows for more advanced filtering. However, this is beyond the scope of this basic introduction to the pipe command.

Conclusion

The pipe command is an invaluable tool when working with Cisco devices. It can save you significant time by allowing you to quickly filter through large amounts of output to find exactly what you're looking for. Whether you're troubleshooting network issues or simply trying to understand a device's configuration, mastering the use of the pipe command will make you much more efficient at the command line.

Practice using these different pipe options with various show commands, and you'll quickly see how much easier it becomes to work with Cisco CLI output.