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
enableIn.
configure terminalConfiguring.
interface gi0/3A port to find later.
description Meeting roomSomething to search for.
endDone.
show running-config | include vlanLowercase. It finds the switchport lines.
show running-config | include VlanCapital V. A different set of lines entirely, on the same box.
show running-config | section GigabitEthernet0/3The interface and everything under it, and it stops at the end of the block.
show running-config | begin interface Vlan1From there to the bottom, which is a different question.
Your turn
Show only the configuration lines that mention the hostname.
show running-config | hostname
Console into a switch
The trap
Concluding something is missing because `| include vlan` found nothing. The line says Vlan, and the filter is case-sensitive.