Cisco – Show IP route output on a single line with regex or other

ciscorouter

I am scripting with Bash, and I need to be able to print route output on a single line. The issue I have is that some routing protocols print the show ip route & show ip eigrp topology & other show ip route output on two lines per prefix.

I want to know if there is any way to get it to print on the same line with a Cisco regex or other command. For example, the BGP route below prints on the same line which is what I need.


NEXUS:

Non-working example – prints info on second line:

router1# show ip eigrp topology all-links vrf X | section 172.19.32.0/20
 P 172.19.32.0/20, 1 successors, FD is 1563136, serno 6042
    via 172.19.47.3 (1563136/1562880), Vlan320, serno 6035 !prints the rest of output on second line.

Cisco Routers:

Working example:

router#show ip route vrf x | i 172.19.0.0/20
B        172.19.0.0/20 [20/0] via 172.19.15.250, 1w3d !BGP is great it shows up on one line.

Non-working example – prints info on second line:

router#show ip route vrf x | i 172.19.32.0/20
D EX     172.19.32.0/20 
       [170/3328] via 172.19.15.42, 7w0d, GigabitEthernet0/0/1 !EIGRP routes suck because it shows the rest of the output on the second line.

This becomes important with the grep statements I need to do in bash for example:

Working example: prints on same line – this can get us what we need.

user@host:~$ ssh router "show ip route vrf x" | grep 172.19.0.0/20
B        172.19.0.0/20 [20/0] via 172.19.15.250, 1w3d

Non-working example: cant' get the second line of output.

user@host:~$ ssh router "show ip route vrf x" | grep 172.19.32.0/20
D EX     172.19.32.0/20 

So, I am just trying to see if anyone knows of a way in Cisco commands or otherwise to get the second line of show ip route & show ip eigrp topology or other show ip route commands.

Best Answer

You are going to have very mixed success with the different Cisco OSes, and different versions (IOS, IOS-XE, NX-OS, etc.) and how things are presented.

For IOS, the show ip rib route command shows what's in the RIB like show ip route, and I suppose it depends on the IOS version, but I see show ip rib route output on single lines where show ip route shows output on two lines.

The show ip cef command shows what's in the FIB, in a very compressed format, just:

 Prefix     Next Hop     Interface