Created
December 19, 2017 16:35
-
-
Save tmattio/689422ca006b3029fac085df4d576300 to your computer and use it in GitHub Desktop.
List lines matching the interfaces in a Cisco configuration file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
def list_interfaces(input_file): | |
with open(input_file) as fp: | |
lines = fp.read().splitlines() | |
for l in lines: | |
match = re.match(r'^Interface (.*)$', l) | |
if match: | |
yield match.group(0) | |
if __name__ == "__main__": | |
input_file = sys.argv[1] | |
interfaces = list_interfaces(input_file) | |
print('\n'.join(interfaces)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment