Hone

Lessons · Network switches · finding one line in three hundred

Filter it, and mind the capital letters

The pipe filters the output of a command. `include` keeps matching lines, `exclude` drops them, `begin` starts from the first match, `section` gives you a line plus the block indented under it.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

A running configuration is three hundred lines and the one you want is somewhere in the middle. And the pattern is case-sensitive, which catches everybody exactly once.

How to think about it

Pick the filter by what you want back: one line, or a whole interface. Then match the capital letters the configuration actually uses.

Worked example

enable
In.
configure terminal
Configuring.
interface gi0/3
A port to find later.
description Meeting room
Something to search for.
end
Done.
show running-config | include vlan
Lowercase. It finds the switchport lines.
show running-config | include Vlan
Capital V. A different set of lines entirely, on the same box.
show running-config | section GigabitEthernet0/3
The interface and everything under it, and it stops at the end of the block.
show running-config | begin interface Vlan1
From there to the bottom, which is a different question.

Your turn

Show only the configuration lines that mention the hostname.

show running-config |  hostname

The trap

Concluding something is missing because `| include vlan` found nothing. The line says Vlan, and the filter is case-sensitive.

Practise finding one line in three hundred on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.