Python netmiko:如何在 'show version' 命令中打印出与 'Cisco IOS Software' 匹配的特定行?

Python netmiko: How to print out specific line matches with 'Cisco IOS Software' in the 'show version' command?

这是 Cisco Switch show version 命令的示例输出。

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:如果在 'show version' 输出中找到字符串 Cisco IOS Software,我想打印整行。

为了更容易理解,让我把show version输出放在变量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.
'''

搜索 if

>>> if 'Cisco IOS Software' in shvar:
...     print('Found ... print line')
... 
Found ... print line
>>> 

或使用 find

搜索
>>> if shvar.find('Cisco IOS Software') > 0:
...     print('Found ... print line')
... 
Found ... print line
>>> 

问题是如何打印与 'Cisco IOS Software' 匹配的行?

期望的输出

Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)

您可以将字符串分成几行。

for line in shvar.split("\n"):
   if 'Cisco IOS Software' in line:
      print(line)