Is there anyone who hasn’t once gave the Show Run or Show Tech-Support command or anything with large output and thought “man… I don’t need to see all this information ” ? At some point you probably realized that you that you can use the pipe -> | <- to filter your results. You may not appreciate the pipe until you have to look at pretty big configuration… but it’s always advantageous to learn to use it.
So if you gave this command show run | ? you would be presented with these useful options for filtering:
R1#show run | ?
append Append redirected output to URL (URLs supporting append operation only)
begin Begin with the line that matches the string
exclude Exclude lines that match the specified string
include Include lines that match the specified string
redirect Redirect output to URL
section Filter a section of output
tee Copy output to URL
I find section to be my favorite pipe filtering choice since it includes all the associated configurations to the configuration lines matched. They are all very helpful options and should be learned and used but they are not the purpose of my post.
The output for the show run | ? command show above would lead you to believe that adding a text string “the specified string” and pressing enter is the full extend of the filtering feature … but that is not the case. If you issue a question mark after the filter type show run | section ? you are presented with the following information
R2#show run | section ?
LINE Regular Expression
exclude Exclude entire section(s) of output
include Include entire section(s) of output
Here we find out that not only are you able to filter based on text, but you can also add a touch of coolsauce to your search with a regular expression. Never heard of a regular expression (regex.regexp)? Here’s a s30 minute tutorial. You know regular expressions but don’t use them? Grab a good cheat sheet and improve get to improving your searching kung fu. That’s why you are here right? You can increase the power of your search exponentially by using regex characters . \ [ ] ^ Here’s a few basic regular expression examples:
0.0 matches 0x0 and 020
t..t matches strings such as test, text, and tart
172\.1\.. matches 18.104.22.168 but not 22.214.171.124
^123 matches 1234, but not 01234
123$ matches 0123, but not 1234
As you become proficient with regular expressions you can do advanced searches with alternation (Joe or Bob, but not Joe and Bob), Multipliers, Ranges and much more. Sky is the limit :-]
Till next time!