01-24-2019 01:14 PM
I want to grep through the output of "show vlan brief" on several kinds of Catalyst switches (mostly 2960s but also a 6880X) running 15.2(1)S. If I save the output to a Linux box I can "grep [0-9]$" and get the same output that "show vlan brief | include [0-9]$" produces. But the IOS version of grep doesn't do anything with the [0-9]$ syntax. Is the regex parser just broken or incomplete or is there a secret sauce hidden away in a file I haven't Googled for correctly yet?
Solved! Go to Solution.
01-28-2019 01:50 PM
Hi there,
The best guide you will find is here, bear witness to how horribly limited it is:
The regex secret sauce is actually hidden in the EEM sub-system:
...fully featured implementation. This is great for working on output generated within your EEM script, but you then need a strategy to extract the results.
It is a mystery why the IOS CLI never used the EEM regex engine. If you want a switching platform with superb CLI regex, take a look an junos.
Cheers,
Seb.
01-24-2019 11:18 PM
here is the regular expression how it works
depends on what IOS, but 15.0X should work.
your command works. on my switch just tested(Version 15.2)
SW1# show vlan brief | include [0-9]$
1 default active Et1/3, Et2/3, Et3/0, Et3/1
Et3/2
9 VLAN0009 active Et3/3
10 VLAN0010 active Et2/0
30 VLAN0030 active Et2/2
100 VLAN0100 active Et2/1
01-25-2019 05:23 AM
Yes, you are repeating what I said, which is that the regular expression works with CLI commands, but not with grep in the shell. And, the pipe to include doesn't work in the shell, either, so you can't start a command with CLI syntax and pipe it to a shell command.
My output:
Switch-5th-Floor-Lab#sh ver
Cisco IOS Software, C2960C Software (C2960c405-UNIVERSALK9-M), Version 15.2(2)E, RELEASE SOFTWARE (fc3)
************************************************
Output deleted
************************************************
Configuration register is 0xF
Switch-5th-Floor-Lab#sh vlan brie | i [0-9]$
1 default active Gi0/2
203 Switch_Floor_5 active Fa0/1, Fa0/2, Fa0/3, Fa0/4
Fa0/5, Fa0/6, Fa0/7, Fa0/8
605 Switch-5thFloor-VOIP active Fa0/1, Fa0/2, Fa0/3, Fa0/4
Fa0/5, Fa0/6, Fa0/7, Fa0/8
Switch-5th-Floor-Lab#term shell
Switch-5th-Floor-Lab#sh vlan brie | grep [0-9]$
1 default active Gi0/2
2 XXXXXXX network active
************************************************
Output deleted
************************************************
200 XXX-EastSection active
************************************************
Output deleted
************************************************
1002 fddi-default act/unsup
1003 trcrf-default act/unsup
1004 fddinet-default act/unsup
1005 trbrf-default act/unsup
Switch-5th-Floor-Lab#
The entire list of VLANs is returned.
Cisco's docs says regular expressions work with their grep, but as far as I can tell, it's just very simple stuff like 2$, which isn't very helpful. I was looking for information from anyone who can tell me if my command line needs tweeking, or if the regular expression parser in the shell in this version of code is just not ready for prime time. It would be nice if you could string commands together with pipes like you can in a real shell, but if the first one chokes then the shell is pretty useless.
01-25-2019 06:52 AM
Oh correct, i was in different context while looking. its is like Linux BSD Grep cisco used.
Still i am not clear what you expect on Compacted prebuild grep in cisco IOS.
This is not like Full shell stack how you see in Linux.
Can you give example what you look, i may be reading wrong.
01-28-2019 05:31 AM
I want to pipe the output to another text utility, like cut (which also does not seem to work correctly, but one question at a time), and then another, and eventually end up with a list of the VLANs without all of the other text the CLI output produces. I can easily come up with any number of command strings to do this on a real Linux box, but I need to save the original output as a file first. It would be nice to avoid that time-consuming step, and I assume that is what cisco intended by creating the terminal shell in the first place. I have tried all kinds of variations on the [0-9]$ syntax, escaping the brackets, using single and double quotes, etc., but as far as I can tell these text utilities are so limited that finding out what they can do takes longer than just doing what I need to do another way.
01-28-2019 01:18 PM
As i have mentioned earlier post this got limited set of commands, you want to full linux based command you can use linux box get out from device and can trim how you like.
you can use expect command.
01-28-2019 01:50 PM
Hi there,
The best guide you will find is here, bear witness to how horribly limited it is:
The regex secret sauce is actually hidden in the EEM sub-system:
...fully featured implementation. This is great for working on output generated within your EEM script, but you then need a strategy to extract the results.
It is a mystery why the IOS CLI never used the EEM regex engine. If you want a switching platform with superb CLI regex, take a look an junos.
Cheers,
Seb.
01-29-2019 06:05 AM
Thank you, Seb. I've done a lot of work in Junos environments, and you're right. My current workplace is Cisco-only, so I was hoping the shell would be useful. Anyway, I didn't know about the EEM, so that will be interesting to look at. Thanks again.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide