Instead of seeing actual
show command output, you might simply want a
count of the number of lines in the output, or the number of lines that match a
regular expression. You can then easily compare the line count with the count
from previous times you entered the command. This can be a quick check as you
make configuration changes. You can either use the
count keyword, or add
-c to the grep keyword.
show
command |
count [regular_expression]
show
command |
grep -c [regular_expression]
Replace
regular_expression with any Cisco IOS regular
expression. The regular expression is not enclosed in quotes or double-quotes,
so be careful with trailing white spaces, which will be taken as part of the
regular expression. The regular expression is optional; if you do not include
one, the count returns the total number of lines in the unfiltered output.
When creating regular expressions, you can use any letter or number
that you want to match. In addition, certain keyboard characters called
metacharacters have special meaning when used in regular expressions. Use
Ctrl+V to escape all of the special characters in the CLI, such as a question
mark (?) or a tab. For example, type
d[Ctrl+V]?g to enter
d?g in the configuration.
For example, to show the total number of all lines in the
show running-config output:
ciscoasa# show running-config | count
Number of lines which match regexp = 271
The following example shows how you can quickly check how many
interfaces are up. The first example shows how to use the
grep keyword with a regular expression to
filter on only those lines that show an up status. The next example adds the
-c option to simply show the count rather
than the actually lines of output.
ciscoasa# show interface | grep is up
Interface GigabitEthernet0/0 "outside", is up, line protocol is up
Interface GigabitEthernet0/1 "inside", is up, line protocol is up
ciscoasa# show interface | grep -c is up
Number of lines which match regexp = 2