这是 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 软件”匹配的行?
期望的输出
Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)