【发布时间】:2020-04-20 05:04:19
【问题描述】:
这是 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.
目标:如果在“显示版本”输出中找到字符串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)
【问题讨论】:
标签: python python-3.x cisco netmiko