netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output (/thread-26056.html) |
netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output - sabrina - Apr-20-2020 This is sample output of Cisco Switch show version command. Switch#show version Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc.Objective: If string Cisco IOS Software is found in show version output, I would like to print the whole line.To make it easier to understand, let me put show version output in variable shvar shvar = ''' Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2012 by Cisco Systems, Inc. '''Search with if >>> if 'Cisco IOS Software' in shvar: ... print('Found ... print line') ... Found ... print line >>>Or Search with find >>> if shvar.find('Cisco IOS Software') > 0: ... print('Found ... print line') ... Found ... print line >>>The question is how do I print the line matches with 'Cisco IOS Software'? Desired Output Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1) RE: netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output - carstenlp - Nov-28-2022 One option is to do : show version | incl IOS Software instead of just show version. Then you are sure you only get that line.. Another option is using regex. I got an example on that specific somewhere, just cant find it right now. :( / carsten (Apr-20-2020, 05:52 AM)sabrina Wrote: This is sample output of Cisco Switch show version command. |