Search code examples
tclcommand-line-interfaceshowciscocisco-ios

Cisco Show command filtering


I am writing a script to capture certain lines of config from a cisco device. Unfortunately the buffer keeps getting filled up. So I was wondering if cisco devices can have 2 include statements. For example:

show start | include vpn && protocol

The 2 lines that I need info from do not have anything in common. I want to avoid using 2 commands. Is there a way I can get both lines with one command?

Another cisco-show related questions is if I can limit the output to the first 10 lines, some thing like:

show start | inc first 10

Solution

  • This example shows a logic "OR"

    R1#show ip int br
    Interface                  IP-Address      OK? Method Status                Protocol
    Ethernet0/0                unassigned      YES TFTP   administratively down down
    Ethernet0/1                192.168.56.11   YES TFTP   up                    up
    Ethernet0/2                unassigned      YES TFTP   administratively down down
    Ethernet0/3                unassigned      YES TFTP   administratively down down
    R1#
    R1#show ip int br | inc Ethernet0/0|192.168.56.11
    Ethernet0/0                unassigned      YES TFTP   administratively down down
    Ethernet0/1                192.168.56.11   YES TFTP   up                    up
    R1#
    

    Another example uses logic "AND" by using regular expressions:

    R1#show ip route
    Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
           D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
           N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
           E1 - OSPF external type 1, E2 - OSPF external type 2
           i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
           ia - IS-IS inter area, * - candidate default, U - per-user static route
           o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
           a - application route
           + - replicated route, % - next hop override
    
    Gateway of last resort is not set
    
          192.168.56.0/24 is variably subnetted, 2 subnets, 2 masks
    C        192.168.56.0/24 is directly connected, Ethernet0/1
    L        192.168.56.11/32 is directly connected, Ethernet0/1
    R1#
    R1#
    R1#show ip route | inc C.*directly connected
    C        192.168.56.0/24 is directly connected, Ethernet0/1
    R1#
    
    • "." means any single character
    • "*" means zero or more instance of preceding character
    • so the pipe basically translate to "C" followed by any character (space/text) then "directly connected"

    Hope this helps