"CDP Neighbor Details" 출력에서 ​​특정 필드를 검색하려면 어떻게 해야 합니까?

"CDP Neighbor Details" 출력에서 ​​특정 필드를 검색하려면 어떻게 해야 합니까?

CDP neighbors detail다음과 같은 터미널 출력이 포함된 텍스트 파일이 있습니다 .

show cdp neighbors detail
-------------------------
Device ID: BIOTERIO
Entry address(es): 
  IP address: 000.000.00.000
Platform: cisco WS-C2950G-24-EI,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/6,  Port ID (outgoing port): GigabitEthernet0/1
Holdtime : 154 sec

Version :
Cisco Internetwork Operating System Software 
IOS (tm) C2950 Software (C2950-I6Q4L2-M), Version 12.1(14)EA1, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2003 by cisco Systems, Inc.
Compiled Tue 22-Jul-03 12:13 by antonino

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000000B5FCA1E00FF0000
VTP Management Domain: ''
Duplex: full
Management address(es): 

-------------------------
 --More--         Device ID: N7K-LAN(JAF1651ANDL)
Entry address(es): 
  IP address: 000.000.0.000
Platform: N7K-C7010,  Capabilities: Router Switch IGMP 
Interface: GigabitEthernet1/0/1,  Port ID (outgoing port): Ethernet7/23
Holdtime : 166 sec

Version :
Cisco Nexus Operating System (NX-OS) Software, Version 7.2(2)D1(2)

advertisement version: 2
VTP Management Domain: 'NULL'
Native VLAN: 1
Duplex: full
Management address(es): 

-------------------------
Device ID: LAB_PESADO
Entry address(es): 
  IP address: 000.000.000.000
Platform: cisco WS-C2960-48TC-S,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/11,  Port ID (outgoing port): GigabitEthernet0/1
Holdtime : 149 sec
 --More--         
Version :
Cisco IOS Software, C2960 Software (C2960-LANLITEK9-M), Version 12.2(50)SE5, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Tue 28-Sep-10 13:44 by prod_rel_team

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF00000000000018339DBD9200FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.000

-------------------------
Device ID: Arquitectura_Salones
Entry address(es): 
  IP address: 000.000.000.00
Platform: cisco WS-C2960S-48TS-S,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/9,  Port ID (outgoing port): GigabitEthernet0/49
 --More--         Holdtime : 129 sec

Version :
Cisco IOS Software, C2960S Software (C2960S-UNIVERSALK9-M), Version 12.2(55)SE2, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2011 by Cisco Systems, Inc.
Compiled Tue 11-Jan-11 02:23 by prod_rel_team

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000E8BA7096A280FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.00

-------------------------
Device ID: CIVIL_253
Entry address(es): 
  IP address: 000.000.000.000
Platform: cisco WS-C2960S-48TS-L,  Capabilities: Switch IGMP 
 --More--         Interface: GigabitEthernet1/0/4,  Port ID (outgoing port): GigabitEthernet1/0/52
Holdtime : 164 sec

Version :
Cisco IOS Software, C2960S Software (C2960S-UNIVERSALK9-M), Version 12.2(55)SE7, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2013 by Cisco Systems, Inc.
Compiled Mon 28-Jan-13 10:28 by prod_rel_team

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000F41FC2105480FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.000

-------------------------
Device ID: Arquitectura
Entry address(es): 
  IP address: 148.228.134.253
 --More--         Platform: cisco WS-C2960-48TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/3,  Port ID (outgoing port): GigabitEthernet0/1
Holdtime : 122 sec

Version :
Cisco IOS Software, C2960 Software (C2960-LANBASE-M), Version 12.2(35)SE5, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2007 by Cisco Systems, Inc.
Compiled Thu 19-Jul-07 20:06 by nachen

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF0000000000000023AC7A0080FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.000

-------------------------
Device ID: ING_CIVIL_DIR
Entry address(es): 
  IP address: 000.000.0.000
 --More--         Platform: cisco WS-C3524-XL,  Capabilities: Trans-Bridge Switch 
Interface: GigabitEthernet1/0/10,  Port ID (outgoing port): GigabitEthernet0/2
Holdtime : 156 sec

Version :
Cisco Internetwork Operating System Software 
IOS (tm) C3500XL Software (C3500XL-C3H2S-M), Version 12.0(5.3)WC(1), MAINTENANCE INTERIM SOFTWARE
Copyright (c) 1986-2001 by cisco Systems, Inc.
Compiled Mon 30-Apr-01 07:51 by devgoyal

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010121FF0000000000000006D779C000FF0001
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 

-------------------------
Device ID: ING_CIVIL
Entry address(es): 
  IP address: 000.000.000.000
 --More--         Platform: cisco WS-C2960-24TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/7,  Port ID (outgoing port): GigabitEthernet0/2
Holdtime : 170 sec

Version :
Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(44)SE6, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2009 by Cisco Systems, Inc.
Compiled Mon 09-Mar-09 18:10 by gereddy

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF0000000000003CDF1ED25100FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.000

-------------------------
Device ID: Ingenieria_Posgrado
Entry address(es): 
  IP address: 148.228.137.253
 --More--         Platform: cisco WS-C2960-24TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/8,  Port ID (outgoing port): GigabitEthernet0/1
Holdtime : 141 sec

Version :
Cisco IOS Software, C2960 Software (C2960-LANBASE-M), Version 12.2(25)SEE3, RELEASE SOFTWARE (fc2)
Copyright (c) 1986-2007 by Cisco Systems, Inc.
Compiled Thu 22-Feb-07 13:57 by myl

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000001CF9AA5200FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.000

-------------------------
Device ID: Biblio_Barragan
Entry address(es): 
  IP address: 000.000.000.00
 --More--         Platform: cisco WS-C2960-24PC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet0/1
Holdtime : 172 sec

Version :
Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(50)SE5, RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2010 by Cisco Systems, Inc.
Compiled Tue 28-Sep-10 13:44 by prod_rel_team

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF0000000000001CAA07C15900FF0000
VTP Management Domain: 'NULL'
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.00

-------------------------
Device ID: Electronica_Edif_3
Entry address(es): 
 --More--           IP address: 000.000.000.000
Platform: cisco WS-C2960-48TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/5,  Port ID (outgoing port): GigabitEthernet0/1
Holdtime : 145 sec

Version :
Cisco IOS Software, C2960 Software (C2960-LANBASE-M), Version 12.2(35)SE5, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2007 by Cisco Systems, Inc.
Compiled Thu 19-Jul-07 20:06 by nachen

advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF000000000000002305468B00FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full
Management address(es): 
  IP address: 000.000.000.000

Barragan_3750>exit
Connection closed by foreign host.
]0;cesar@cesar-HP-Pavilion-15-NoteBook-PC: ~cesar@cesar-HP-Pavilion-15-NoteBook-PC:~$ 

각 장치에 대해 장치 ID, IP 주소, 인터페이스, 포트 ID(아웃바운드 포트) 필드를 필터링하고 싶습니다.

"장치 ID"라는 단어가 나타날 때마다 검색하고 "포트 ID"가 나타날 때까지 저장하여 다음과 같은 파일을 얻으려고 시도했지만 성공하지 못했습니다.

Device ID: BIOTERIO
Entry address(es): 
  IP address: 000.000.00.000
Platform: cisco WS-C2950G-24-EI,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/6,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------
Device ID: N7K-LAN(JAF1651ANDL)
Entry address(es): 
  IP address: 000.000.0.000
Platform: N7K-C7010,  Capabilities: Router Switch IGMP 
Interface: GigabitEthernet1/0/1,  Port ID (outgoing port): Ethernet7/23

-------------------------
Device ID: LAB_PESADO
Entry address(es): 
  IP address: 000.000.000.000
Platform: cisco WS-C2960-48TC-S,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/11,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------
Device ID: Arquitectura_Salones
Entry address(es): 
  IP address: 000.000.000.00
Platform: cisco WS-C2960S-48TS-S,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/9,  Port ID (outgoing port): GigabitEthernet0/49

-------------------------
Device ID: CIVIL_253
Entry address(es): 
  IP address: 000.000.000.000
Platform: cisco WS-C2960S-48TS-L,  Capabilities: Switch IGMP 
 --More--         Interface: GigabitEthernet1/0/4,  Port ID (outgoing port): GigabitEthernet1/0/52

-------------------------
Device ID: Arquitectura
Entry address(es): 
  IP address: 000.000.000.000
 --More--         Platform: cisco WS-C2960-48TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/3,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------
Device ID: ING_CIVIL_DIR
Entry address(es): 
  IP address: 000.000.0.000
 --More--         Platform: cisco WS-C3524-XL,  Capabilities: Trans-Bridge Switch 
Interface: GigabitEthernet1/0/10,  Port ID (outgoing port): GigabitEthernet0/2

-------------------------
Device ID: ING_CIVIL
Entry address(es): 
  IP address: 000.000.000.000
 --More--         Platform: cisco WS-C2960-24TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/7,  Port ID (outgoing port): GigabitEthernet0/2

-------------------------
Device ID: Ingenieria_Posgrado
Entry address(es): 
  IP address: 000.000.000.000
 --More--         Platform: cisco WS-C2960-24TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/8,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------
Device ID: Biblio_Barragan
Entry address(es): 
  IP address: 000.000.000.00
 --More--         Platform: cisco WS-C2960-24PC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------
Device ID: Electronica_Edif_3
Entry address(es): 
 --More--           IP address: 000.000.000.000
Platform: cisco WS-C2960-48TC-L,  Capabilities: Switch IGMP 
Interface: GigabitEthernet1/0/5,  Port ID (outgoing port): GigabitEthernet0/1

-------------------------

이 문제를 해결하는 데 도움을 주실 수 있나요?

또는

이 정보를 얻는 더 좋은 방법을 알고 있나요?

답변1

그러면 찾고 있는 필드와 일치하는 모든 줄이 인쇄됩니다.

awk '/Device ID|IP address|Interface|Port ID/ { print }' /path/to/input

grepsed및 기타 유사한 도구를 사용하여 동일한 작업을 수행 할 수 있습니다 .

조금 더 좋아질 수도 있습니다.

grep -Eo '(Device ID|IP address|Interface|Port ID): [^ ]+' /path/to/input

답변2

awk 대신 egrep을 사용할 수 있는 옵션이 있습니까?

egrep "Device|IP\ address|Interface|Port\ ID" input-file.txt

답변3

GB 단위의 로그 파일이 아닌 경우

 perl -0ne 'for( /Device ID.*?Port ID.*?\n/sg ){ print "-"x 20,"\n$_\n"}' file

관련 정보