More Useful Output Modifiers

Quick and Easy Tricks to Streamline Your IOS CLI Skills

In my introductory post, we looked at some of the more obscure output modifiers, such as the "redirect" and "append" filters. In this post, we'll look at some of the more common ones. Most people who have been around IOS for a while know about the "begin", "include", and "exclude" modifiers. The utility of these tools is limited primarily by one's creativity, but at the risk of blogging the obvious, I want to show some of my favorites.Show Only Interfaces with Assigned AddressesBefore

The "show ip interface brief" command is ubiquitous in almost everyone's IOS arsenal. On a platform with a lot of interfaces, though, many of those interfaces will frequently not have IP addresses assigned to them. Layer 3 switches and PRI gateways are two particularly common examples where this happens. You can filter out all of the unassigned interfaces with a simple exclusion filter, leaving only the ones that are likely to be interesting. Specifically, we use the "exclude" output modifier to remove lines with the "unassigned" word from the display.

Switch#show ip interface brief

Interface IP-Address OK? Method Status Protocol

Vlan1 unassigned YES unset administratively down down

FastEthernet1/0/1 10.1.1.1 YES manual down down

FastEthernet1/0/2 unassigned YES unset down down

FastEthernet1/0/3 unassigned YES unset down down

FastEthernet1/0/4 unassigned YES unset down down

After

BeforeSwitch#sh int status

Switch#sh ip int b | exclude un

Interface IP-Address OK? Method Status Protocol

FastEthernet1/0/1 10.1.1.1 YES manual down down

Show Only Connected Switch Interfaces

In this case, we'll use an exclusion filter to remove lines with "not" in them, thus removing all interfaces from the display that are in the "notconnect" state. Note that I've shortened "exclude" to "e" as a time-saver.

Fa1/0/13 notconnect 1 auto auto 10/100BaseTX

Fa1/0/14 notconnect 1 auto auto 10/100BaseTX

Fa1/0/15 notconnect 1 auto auto 10/100BaseTX

Fa1/0/16 notconnect 1 auto auto 10/100BaseTX

Gi1/0/1 notconnect 1 auto auto 10/100/1000BaseTX

Gi1/0/2 connected 1 full 1000 No PHY XCVR

After

Switch#sh int status | e notPort Name Status Vlan Duplex Speed TypeWhen I was teaching Cisco classes, many students were annoyed that there's no built-in command that displays a list of all interface names and IP addresses along with the relevant subnet mask. You can use a regular expression to get around this annoyance:TEST#sh ip int | i line|/..$I'm not going to go into a detailed explanation of how regular expressions work--there are many good tutorials available via a web search, as well as several good books on the subject. Suffice to say that the command expression above translates into English like this:"take the 'show ip interface' command, and from the output include only lines that include the string "line" OR a string that ends with a "/" character followed by two characters."The result is that we see the interface name for all interfaces, followed by the IP address and mask in CIDR format. It's not perfect: for example, it will display all interface names, even if there's no address assigned to them. Also, it shows interfaces that are down, which might not be desirable. We might come up with workarounds for these problems by making different or more complex regular expressions, but the point of this blog is to show quick, easy-to-remember tricks that will help you in day-to-day operations, even at the expense of imperfections. Feel free to include your favorites in the comments.Here are a couple of other favorites of mine:Show Only Non-Phone CDP NeighborsTEST-sw#sh cdp n | e SEP178           T     AIR-LAP113 Fas 0Since Cisco IP phones have a device ID that begins with "SEP" (which stand for "Selsius Ethernet Phone", by the way), this is a quick way to get only non-phone neighbors, which is handy on a large IP telephony access switch.TEST-sw#sh int status | i _4_This produces a nicely formatted table. The underscores in the regular expression represent spaces, and ensure that we don't include interfaces that simply have names that end in 4, such as "Fa1/0/4".

Gi1/0/2 connected 1 full 1000 No PHY XCVR

Adding Regular Expressions

The output modifiers all support the use of Cisco's regular expression syntax, which is quite similar to most other Unix-derived regex syntax. By using regular expressions creatively, we can come up with some pretty nice permutations of "show" commands. Although you can do complex things with regular expressions, I try to keep them simple enough that I can remember them easily and type them quickly (you can get around this requirement by using aliases, which we might discuss later).

FastEthernet0/0 is up, line protocol is down

  Internet address is 10.60.18.42/24

FastEthernet0/1 is administratively down, line protocol is down

Loopback1 is up, line protocol is up

  Internet address is 1.1.1.1/24

Loopback2 is up, line protocol is up

  Internet address is 2.2.2.2/25

Loopback3 is administratively down, line protocol is down

  Internet address is 3.3.3.3/26

  Secondary address 3.3.3.100/29

[output omitted]

Device ID       Local Intrfce    Holdtme   Capability    Platform   Port ID

ap.cisco.com    Fas 0/38             

Show Only Ports in a Specific VLAN

Fa1/0/1   PC/Phone port      notconnect   4            auto   auto 10/100BaseTX

Fa1/0/2   PC/Phone port      connected    4          a-full  a-100 10/100BaseTX

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.
Related:

Copyright © 2010 IDG Communications, Inc.