9

So aggravating - i can't find good documentation on how to use the Nexus regex command.

So, if my interfaces look like this:

interface Vlan224
  description MANAGEMENT
  no shutdown
  ip flow monitor netflow-monitor input  
  no ip redirects
  ip address 10.214.224.2/24
  ip ospf passive-interface
  ip router ospf 1 area 0.0.0.3
  ip pim sparse-mode
  hsrp version 2
  hsrp 224 
  preempt 
  priority 120
  ip 10.214.224.1 

I want to run something similar to:

show run | inc (interface Vlan)|(ip address)

And the output to look similar to (if this were on IOS):

interface Vlan10
ip address 10.1.10.1 255.255.255.0
interface Vlan 11
ip address 10.1.11.1 255.255.255.0
etc.
8

You can do a show run | egrep interface.Vlan|ip.address. It does grab a bit more info, but should provide similar output to what you see in IOS. I think grep might work as well, but I used egrep and got the correct output.

5

If you are just looking for the IP addresses of the Vlan interfaces, a better way may be: show ip int br | grep -i vlan

Note: show ip int br in NXOS only shows layer 3 interfaces. To see status of all interfaces use show int br

UPDATE:

for NXOS 4.0(2) and earlier: show run | grep -i face\ vlan|ip\ address

4.0(3) and up: show run | grep ignore-case face\ vlan|ip\ address

also the \ is how to escape the space with regex. Link for the NXOS regex: http://www.cisco.com/en/US/docs/switches/datacenter/sw/4_0/nx-os/fundamentals/configuration/guide2/fun_3about_cli.html#wp1237003

  • I also want to have info on the subnet information, so that's why I was trying to pull it out of the "show run". – Pseudocyber May 30 '13 at 15:17
  • I see. Then try this one on for size: show run | grep -i face\ vlan|ip\ address this will also show all lines in the output that contain either "face vlan" or "ip address" – emynd May 30 '13 at 15:19
  • Richard, thanks, but get a carrot under the f after grep -i – Pseudocyber May 30 '13 at 17:06
  • should have looked deeper, my apologies. That syntax should work on NXOS 4.0(2) and earlier. For 4.0(3) and up replace -i with ignore_case here's the link cisco.com/en/US/docs/switches/datacenter/sw/4_0/nx-os/… – emynd May 30 '13 at 17:27
  • Richard S, so it sounds like what I used to be able to do in ios with a | inc, I now need to do in NXOS with a | grep ignore-case blah blah blah. And spaces need to be escaped, like this "\ " without quotes? and I can still use multiple |'s to use as logical or's? – Pseudocyber May 30 '13 at 17:49
5

An alternate syntax involving single quotes.

# show run | inc 'interface Vlan|ip address'

In NX-OS, argument parsing works a lot like bash.

3

The documentation I have seen says this should work:

show run | inc interface_Vlan|ip_address

Although it does not seem to for me on a 4k blade switch. I had success with

sh run | inc interface.Vlan|ip.address
  • That doesn't work on a 7K. 7K# sh run | inc interface_Vlan|ip_address 7K# sh run | inc interface_Vlan | ip_address - puts a carrot under the p. No output at all. – Pseudocyber May 30 '13 at 15:08
  • I don't have Nexus to try it on but you might try (interface.Vlan|ip.address). The ^ under the p sounds like it's interpreting the "|i" as a second pipe. – Dave Noonan May 30 '13 at 15:22
  • @Pseudocyber: *caret :-) – Paul Gear May 30 '13 at 23:05
  • Per docs, and unlike IOS, "the underscore is only treated as a regular expression for BPG related commands" – belacqua Mar 6 '14 at 20:50
0

The easy answer is that, for a one-to-one mapping from IOS to NX-OS, it looks like this:

IOS: show run | inc (interface Vlan)|(ip address)
NX-OS: show run | inc 'interface Vlan|ip address'

Note that this makes more sense when you leave out the extra parens in the original:

show run | inc (interface Vlan|ip address)

The key in this example is that for NX-OS, the parens are replaced by quote marks.

You could also use double quotes, i.e. "" .

NX-OS is Linux-based[1], and uses a *nix-like regular expression engine. The commands are odd comprises between English wording and standard regex idioms.

For example, what would be egrep -v in bash would look like egrep ignore-case
On the command line this would look something like

show run | egrep ignore-case vpc
or
show run | inc ignore-case vpc

An example of the verbosity (and strength) of the new regex features:
show run | egrep ignore-case vpc | egrep invert-match ignore-case peer

This would be equivalent to a bash-shell egrep -i vpc <input> | egrep -vi peer

Nevertheless, there is considerably more power and flexibility here than in current IOS.

The basic Cisco documentation is here*, but your command-line ? feature gives you quick reminders:

5k# show run | ?
  cut      Print selected parts of lines.
  diff     Show difference between current and previous invocation (creates temp files: remove them
           with 'diff-clean' command and dont use it on commands with big outputs, like 'show 
           tech'!) 
  egrep    Egrep - print lines matching a pattern
  grep     Grep - print lines matching a pattern
  head     Display first lines
  human    Output in human format
  last     Display last lines
  less     Filter for paging
  no-more  Turn-off pagination for command output
  section  Show lines that include the pattern as well as the subsequent lines that are more
           indented than matching line 
  sort     Stream Sorter
  tr       Translate, squeeze, and/or delete characters
  uniq     Discard all but one of successive identical lines
  vsh      The shell that understands cli command
  wc       Count words, lines, characters
  xml      Output in xml format (according to .xsd definitions)
  begin    Begin with the line that matches
  count    Count number of lines
  end      End with the line that matches
  exclude  Exclude lines that match
  include  Include lines that match

5k# show run | inc ?
  WORD         Search for the expression
  ignore-case  Ignore case difference when comparing strings
  line-exp     Print only lines where the match is a whole line

5k# show run | egrep ?
  WORD          Search for the expression
  count         Print a total count of matching lines only
  ignore-case   Ignore case difference when comparing strings
  invert-match  Print only lines that contain no matches for <expr>
  line-exp      Print only lines where the match is a whole line
  line-number   Print each match preceded by its line number
  next          Print <num> lines of context after every matching line
  prev          Print <num> lines of context before every matching line
  word-exp      Print only lines where the match is a complete word

You'll then want to search "fun" (what else?) to find the Fundamentals Configuration Guide (which contains the Regular Expression section in the Understanding the Command-Line Interface chapter).

Easter egg? Chapter numbers are in binary for this doc.

If you walk through the docs, you'll find a lot more *nix-like command-line tools, including cut, tr, and on the 7K, sed and some other goodies.

Also, don't overlook the prev and next modifiers for 'include' matches.

This will grab lines containing foo, as well as three lines before and two lines after for context:
show run | inc foo prev 3 next 2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.