In order to have a record of the devices connected to a network I'm working on an Expect script that takes information from the command Show CDP neighbors detail and saves certain fields including Device Name, IP address, Interface and Port ID (outgoing port), any of those fields work as a primary key in my Database, not even IP address cause the same IP address doesn't guaranty it is the same device. For that reason I need to catch the S/N of each device with the command show inventory, I've got both command's output in separate text files and now I need to match the information.file1:Device ID: BIOTERIO  IP address: 000.000.00.001Interface: GigabitEthernet1/0/6,  Port ID (outgoing port): GigabitEthernet0/1Device ID: N7K-LAN(JAF1651ANDL)  IP address: 000.000.0.002Interface: GigabitEthernet1/0/1,  Port ID (outgoing port): Ethernet7/23Device ID: LAB_PESADO --More--           IP address: 000.000.000.003Interface: GigabitEthernet1/0/11,  Port ID (outgoing port): GigabitEthernet0/1  IP address: 000.000.000.003Device ID: Arquitectura_Salones  IP address: 000.000.000.04Interface: GigabitEthernet1/0/9,  Port ID (outgoing port): GigabitEthernet0/49  IP address: 000.000.000.04Device ID: CIVIL_253  IP address: 000.000.000.005Interface: GigabitEthernet1/0/4,  Port ID (outgoing port): GigabitEthernet1/0/52  IP address: 000.000.000.005Device ID: Arquitectura  IP address: 000.000.000.006Interface: GigabitEthernet1/0/3,  Port ID (outgoing port): GigabitEthernet0/1  IP address: 000.000.000.006Device ID: ING_CIVIL_DIR  IP address: 000.000.0.007Interface: GigabitEthernet1/0/10,  Port ID (outgoing port): GigabitEthernet0/2Device ID: ING_CIVIL  IP address: 000.000.000.008Interface: GigabitEthernet1/0/7,  Port ID (outgoing port): GigabitEthernet0/2  IP address: 000.000.000.008Device ID: Ingenieria_Posgrado  IP address: 000.000.000.009Interface: GigabitEthernet1/0/8,  Port ID (outgoing port): GigabitEthernet0/1  IP address: 000.000.000.009Device ID: Biblio_Barragan  IP address: 000.000.000.10Interface: GigabitEthernet1/0/2,  Port ID (outgoing port): GigabitEthernet0/1  IP address: 000.000.000.10Device ID: Electronica_Edif_3  IP address: 000.000.000.011Interface: GigabitEthernet1/0/5,  Port ID (outgoing port): GigabitEthernet0/1  IP address: 000.000.000.011]0;cesar@cesar-HP-Pavilion-15-NoteBook-PC: ~cesar@cesar-HP-Pavilion-15-NoteBook-PC:~$ awk '/Device ID|IP address|Interface|Port ID/ { print }' CDPdet.dat >tabladetallada.dat file 2:show inventoryNAME: 1, DESCR: WS-C3750G-12SPID: WS-C3750G-12S-E   , VID: V06, SN: FDO1130Z9ZJNAME: GigabitEthernet1/0/1, DESCR: 1000BaseLX SFPPID:                     , VID:    , SN: H006K082        NAME: GigabitEthernet1/0/2, DESCR: 10/100/1000BaseTX SFPPID: GLC-T               , VID:    , SN: 00000MTC1666080ZNAME: GigabitEthernet1/0/3, DESCR: 1000BaseLX SFPPID:                     , VID:    , SN: H118K083        NAME: GigabitEthernet1/0/4, DESCR: 1000BaseLX SFPPID:                     , VID:    , SN: H006K041        NAME: GigabitEthernet1/0/5, DESCR: 1000BaseSX SFPPID:                     , VID:    , SN: FNS11140FLE     NAME: GigabitEthernet1/0/6, DESCR: 1000BaseSX SFPPID:                     , VID:    , SN: P7K06UQ         NAME: GigabitEthernet1/0/7, DESCR: 1000BaseLX SFPPID:                     , VID:    , SN: H006K052        NAME: GigabitEthernet1/0/8, DESCR: 1000BaseLX SFPPID:                     , VID:    , SN: H006K030        NAME: GigabitEthernet1/0/9, DESCR: 1000BaseLX SFPPID:                     , VID:    , SN: FNS14200533     NAME: GigabitEthernet1/0/10, DESCR: 1000BaseLX SFPPID: GLC-LH-SMD          , VID: V86, SN: FNS14201SG0     NAME: GigabitEthernet1/0/11, DESCR: 1000BaseLX SFPPID: GLC-LH-SMD          , VID: V86, SN: FNS174202FT     NAME: GigabitEthernet1/0/12, DESCR: 1000BaseLX SFPPID: GLC-LH-SMD          , VID: V86, SN: FNS184203FS     Barragan_3750>I would like to have all the information placed in the same file and in the correct order, something like this:Device ID: BIOTERIOIP address: 000.000.00.001Interface: GigabitEthernet1/0/6  Port ID (outgoing port): GigabitEthernet0/1SN: P7K06UQDevice ID: N7K-LAN(JAF1651ANDL)IP address: 000.000.0.002Interface: GigabitEthernet1/0/1  Port ID (outgoing port): Ethernet7/23SN: H006K082Device ID: LAB_PESADOIP address: 000.000.000.003Interface: GigabitEthernet1/0/11Port ID (outgoing port): GigabitEthernet0/1SN: FNS174202FT...etcDoes anybody know how to do that using grep, awk or perl?
Match data from two different files
text processing;awk;grep;perl
#!/bin/bashFILE1=file1FILE2=file2while read line; do    if [[ $line == Device\ ID* ]]; then        echo -e \n$line        expectIp=1    elif [[ $line == *IP\ address* && $expectIp -eq 1 ]]; then        sed 's/^\s*//' <<< $line        unset expectIp    elif [[ $line == Interface* ]]; then        interface=$(echo $line | grep -o 'Interface[^,]*,' | sed 's/,//')        echo $interface        echo $line | grep -o 'Port ID.*'        justInterface=$(echo $interface | sed 's/Interface: //')        grep -A1 \$justInterface\ $FILE2 | grep -o 'SN: .*'    fidone < $FILE1