Learn to write your own RegEx Parser Part 3/9:Cisco Show command parser Python RegEx Tutorial

Published: 26 March 2021
on channel: NetworkEvolution
2,545
27

#PythonRegex #CiscoParser #RegexTutorial

Playlist: Learn to Parse Cisco Configuration using Python RegEx:re Tutorial
   • Learn to Parse Cisco Configuration using P...  

Playlist: Python Learning for Network Engineers
   • Python learning for Network Engineers | Pa...  

Playlist: Learn to Read Data From CSV Using Python
   • Learn to Read Data from CSV (IP/Config): P...  

Playlist: Paramiko detailed explanation with Example for Network Engineers
   • Paramiko Tutorial :Part1  How SSH Host key...  

This video demonstrates how to parse Cisco configuration using Parser in python
how to parse cisco configuration,how to parse cisco output using python,python regex cisco parsing,python regex for beginners,re library tutorial,
Regular expression for Cisco show command
How to parse hostname, serial number uptime of Cisco devices from show version command output
Python re library tutorial
Script
-----------
import re

version_pattern = re.compile(r'Cisco .+ Software, Version (\S+)\n')
model_pattern = re.compile(r'cisco (\S+).+bytes of memory\.')
serial_no_pattern = re.compile(r'Processor board ID (\S+)')
uptime_pattern = re.compile(r'(.+) uptime is (.*)')

with open('01_show_version_output.txt', 'r') as file:
output = file.read()

version_match = version_pattern.search(output)
print('IOS Version'.ljust(18)+': '+version_match.group(1))

model_match = model_pattern.search(output)
print('Model '.ljust(18)+': '+model_match.group(1))

serial_no_match = serial_no_pattern.search(output)
print('Serial Number '.ljust(18)+': '+serial_no_match.group(1))

uptime_match = uptime_pattern.search(output)
print('Host Name '.ljust(18)+': '+uptime_match.group(1))
print('Device Uptime '.ljust(18)+': '+uptime_match.group(2))

-----------


On this page of the site you can watch the video online Learn to write your own RegEx Parser Part 3/9:Cisco Show command parser Python RegEx Tutorial with a duration of hours minute second in good quality, which was uploaded by the user NetworkEvolution 26 March 2021, share the link with friends and acquaintances, this video has already been watched 2,545 times on youtube and it was liked by 27 viewers. Enjoy your viewing!