{"id":2186,"date":"2015-04-22T16:33:19","date_gmt":"2015-04-22T15:33:19","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?p=2186"},"modified":"2015-04-22T16:33:19","modified_gmt":"2015-04-22T15:33:19","slug":"filtering-cisco-show-output-using-regular-expressions","status":"publish","type":"post","link":"http:\/\/darenmatthews.com\/blog\/?p=2186","title":{"rendered":"Filtering Cisco &#8220;show&#8221; Output Using Regular Expressions"},"content":{"rendered":"<p>show run | i ^interface|^_ip address<br \/>\n! Gives you the every line in your running config that starts with (that\u2019s what the ^ is all about) \u201cinterface\u201d or \u201d ip address\u201d, essentially giving you all of your interface IP\u2019s in an IOS-pastable format.\u00a0 The underscore represents a space.\u00a0 Useful for displaying IP addresses with their associated masks and interfaces.<!--more--><\/p>\n<p>show ip interf brief | e unassigned<br \/>\n! Shows you all of the IP-capable interfaces on the box, except for the ones that have not been assigned an IP address.\u00a0 I use this often, especially on big switch\/routers where most of the physical interfaces do not have an IP addresses, but the SVIs do.<\/p>\n<p>show run | i ip route.*Serial1\/1<br \/>\n! Shows you all static routes in your configuration pointing out Serial1\/1, no matter what they are.\u00a0 Substitute your own interface name.\u00a0 Useful if you\u2019re doing clean up after decommissioning an interface where you didn\u2019t run a dynamic routing protocol.<\/p>\n<p>show interf status | i Gi[2-6]\/20<br \/>\n! Shows you the status of all port 20s in slots 2-6 of a chassis with gig cards.\u00a0 Putting the 2-6 in square brackets is a regex telling the parser that any character that\u2019s 2 through 6 inclusive is a match.<\/p>\n<p>show interf status | i Gi[246]\/20<br \/>\n! Shows you the status of all port 20s in slots 2, 4, and 6 of a chassis with gig cards.\u00a0 Here, [246] tells the parser that values 2, 4, or 6 are all matches for that position.<\/p>\n<p>show interf status | i Gi.\/2_<br \/>\n! Shows you the status of all ports ending in 2.\u00a0 The underscore represents a space, so this makes sure you don\u2019t get a match for \u201c20\u201d or \u201c22\u201d when all you really want is \u201c2\u201d.\u00a0 The dot is a wildcard, allowing for any single character in that position.\u00a0 If you want to match a random number of additional wildcard characters, follow the dot with an asterisk.<\/p>\n<p>show interf status | i Gi7\/(29|3[0-9])<br \/>\n! Shows you the status of all ports in slot 7, 29 \u2013 39 inclusive.\u00a0 You get the \u201cGi7\/\u201d, right?\u00a0 No regex magic there.\u00a0 The \u201c29|\u201d could be translated \u201c29 or\u201d.\u00a0 The \u201c3[0-9]\u201d could be translated \u201c3 followed by any of the digits 0 through 9 inclusive\u201d.\u00a0 Put it all together, and you get a match for any line containing Gi7\/, followed by 29 or 30-39.<\/p>\n<p>show interf status | i _101_<br \/>\n! Displays all lines contain the number 101 with a leading and trailing space.\u00a0 Useful if you want to show all the ports in a particular VLAN, in this case 101.<\/p>\n<p>show inter status | i a-100_|_100_<br \/>\n! Displays all the ports that are running at 100Mbps, whether statically defined or auto-negotiated.\u00a0 Will also match interfaces in Vlan100, though.\u00a0 Sadly, Cisco does not allow you to pipe to \u201cinclude\u201d and then further pipe to \u201cexclude\u201d, such as you can do in *nix by nesting piped greps.\u00a0 If you could nest your pipe commands in the IOS CLI, there could be some very interesting output filters generated.<\/p>\n<p>show interface | i line|escription|bits<br \/>\n! Presents all interfaces, their descriptions, and the bits per second flowing through them, both input and output.\u00a0 Does not distinguish between up\/down status.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>show run | i ^interface|^_ip address ! Gives you the every line in your running config that starts with (that\u2019s what the ^ is all about) \u201cinterface\u201d or \u201d ip address\u201d, essentially giving you all of your interface IP\u2019s in an IOS-pastable format.\u00a0 The underscore represents a space.\u00a0 Useful for displaying IP addresses with their [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83],"tags":[],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2186"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2186"}],"version-history":[{"count":1,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2186\/revisions"}],"predecessor-version":[{"id":2187,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2186\/revisions\/2187"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2186"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}