一个简单的答案是,对于从IOS到NX-OS的一对一映射,它看起来像这样:
IOS:show run | inc (interface Vlan)|(ip address)
NX-OS: show run | inc 'interface Vlan|ip address'
请注意,当您在原件中省去多余的括号时,这更有意义:
show run | inc (interface Vlan|ip address)
此示例中的关键是对于NX-OS,括号被引号替换。
您也可以使用双引号,即""
。
NX-OS基于Linux [1],并使用类似于* nix的正则表达式引擎。这些命令在英语措辞和标准正则表达式惯用语之间是奇怪的。
例如,egrep -v
bash中的内容将类似于:egrep ignore-case
在命令行中,其内容类似于
show run | egrep ignore-case vpc
要么
show run | inc ignore-case vpc
新正则表达式功能的冗长(和强度)示例:
show run | egrep ignore-case vpc | egrep invert-match ignore-case peer
这相当于一个bash shell egrep -i vpc <input> | egrep -vi peer
但是,这里的功能和灵活性要比当前的IOS大得多。
基本的Cisco文档在这里 *,但是您的命令行?
功能可以快速提醒您:
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
然后,您将需要搜索“ fun”(还有什么?)以找到“ 基础配置指南”(其中包含“ 了解命令行界面”一章中的“正则表达式”部分)。
复活节彩蛋?本文档的章节编号是二进制的。
如果你走过的文档,你会发现有更多的* nix样的命令行工具,包括cut
,tr
,并在7K,sed
和其他一些东西。
另外,请不要忽略“ include”匹配项的prev
and next
修饰符。
这将获取包含foo的行以及上下文的前三行和后两行:
show run | inc foo prev 3 next 2