Skip to content

Instantly share code, notes, and snippets.

@tmattio
Created December 19, 2017 16:35
Show Gist options
  • Save tmattio/689422ca006b3029fac085df4d576300 to your computer and use it in GitHub Desktop.
Save tmattio/689422ca006b3029fac085df4d576300 to your computer and use it in GitHub Desktop.
List lines matching the interfaces in a Cisco configuration file
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