这是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.
目标:如果在“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软件”匹配的行
期望输出
Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 15.0(2)SE, RELEASE SOFTWARE (fc1)
你可以把绳子分成几行
相关问题 更多 >
编程相关推荐