join files cisco command output

We have two files with results of two commands of cisco:

one file; showintstatus, have the following format:

Gi2/6   servidorlij connected    176          full   1000 10/100/1000BaseT

second file; showmacaddrestable, have the following format:

*  162  0021.9b8d.073e   dynamic  Yes          0   Gi4/39

The important fields are $2,$3,$7.

And when join the two files have some problems because some ports have several mac address and the result is:

Gi2/11  serverusa         connected    176          full   1000 10/100/1000BaseT 176 0019b9e365d6 Gi2/11 176 001d09f0a40d Gi2/11 176 002497f8e8cb Gi2/11 176 0001d7711f05 Gi2/11

I'm looking for the next result when in the port have more than one mac address:

Gi2/11  serverusa         connected    176          full   1000  10/100/1000BaseT 176 0019b9e365d6 Gi2/11
Gi2/11  serverusa        connected    176          full   1000  10/100/1000BaseT 176 001d09f0a40d Gi2/11
Gi2/11  serverusa         connected    176          full   1000  10/100/1000BaseT 176 002497f8e8cb Gi2/11
Gi2/11  serverusa         connected    176          full   1000  10/100/1000BaseT 176 0001d7711f05 Gi2/11

the script that use:

#!/bin/bash

for i in $( more ports ); do
cat showintstatus.2 showmacaddresstable.1 | grep -w $i | awk -vORS=' ' 1
echo -e "\n"
done

the file ports contain a list of ports with the format:

Gi2/13
Gi2/14
Gi2/15
Gi2/16
Gi2/17

I'm newbie in this area and will be appreciate your help

$
$
$ cat ports
Gi2/11
Gi2/14
Gi2/15
Gi2/16
Gi2/17
$
$
$ cat showintstatus
Gi2/11 serverusa connected 176 full 1000 10/100/1000BaseT
Gi2/14 serverusa connected 199 full 1000 10/100/1000BaseT
Gi2/20 serverusa connected 210 full 1000 10/100/1000BaseT
Gi2/16 serverusa connected 220 full 1000 10/100/1000BaseT
$
$
$ cat showmacaddresstable
176 0019b9e365d6 Gi2/11
176 001d09f0a40d Gi2/11
176 002497f8e8cb Gi2/11
199 0001d7711f05 Gi2/14
210 0001e9933y08 Gi2/20
230 0002w7654z01 Gi2/17
$
$
$ ##
$ awk 'FILENAME == "ports" {x[$0] = "y"}
       FILENAME == "showintstatus" && x[$1] == "y" {x[$1] = $0}
       FILENAME == "showmacaddresstable" && x[$3] != "" && x[$3] != "y" {print x[$3],$0}
      ' ports showintstatus showmacaddresstable
Gi2/11 serverusa connected 176 full 1000 10/100/1000BaseT 176 0019b9e365d6 Gi2/11
Gi2/11 serverusa connected 176 full 1000 10/100/1000BaseT 176 001d09f0a40d Gi2/11
Gi2/11 serverusa connected 176 full 1000 10/100/1000BaseT 176 002497f8e8cb Gi2/11
Gi2/14 serverusa connected 199 full 1000 10/100/1000BaseT 199 0001d7711f05 Gi2/14
$
$

tyler_durden

1 Like