join files cisco command output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting join files cisco command output
# 1  
Old 11-10-2010
join files cisco command output

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

one file; showintstatus, have the following format:
Code:
Gi2/6   servidorlij connected    176          full   1000 10/100/1000BaseT

second file; showmacaddrestable, have the following format:
Code:
*  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:
Code:
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:
Code:
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:
Code:
#!/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:

Code:
Gi2/13
Gi2/14
Gi2/15
Gi2/16
Gi2/17

I'm newbie in this area and will be appreciate your help
Moderator's Comments:
Mod Comment Please use code tags when posting data/code samples.

Last edited by vgersh99; 11-10-2010 at 11:32 AM.. Reason: Code tags, please!
# 2  
Old 11-10-2010
Code:
$
$
$ 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
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join two files combining multiple columns and produce mix and match output

I would like to join two files when two columns in each file matches with each other and then produce an output when taking multiple columns. Like I have file A 1234,ABCD,23,JOHN,NJ,USA 2345,ABCD,24,SAM,NY,USA 5678,GHIJ,24,TOM,NY,USA 5678,WXYZ,27,MAT,NJ,USA and file B ... (2 Replies)
Discussion started by: mady135
2 Replies

2. Shell Programming and Scripting

How to join output of two command in same line?

Hi I am trying to figureout how to join output of two command in unix in the same line. for e.g. $ankit : df -h | egrep -w /home | awk '{print -n $1 "\t" $5}' ;stat --format=%a /home Output: 0148G /home 775 I want this output as... 0148G /home 775 Please let me know if you... (7 Replies)
Discussion started by: kotak86
7 Replies

3. UNIX for Dummies Questions & Answers

How to use the the join command to join multiple files by a common column

Hi, I have 20 tab delimited text files that have a common column (column 1). The files are named GSM1.txt through GSM20.txt. Each file has 3 columns (2 other columns in addition to the first common column). I want to write a script to join the files by the first common column so that in the... (5 Replies)
Discussion started by: evelibertine
5 Replies

4. UNIX for Dummies Questions & Answers

How to use the join command to obtain tab delimited text files as an output?

How do you use the join command and obtain tab delimited text files as an output? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

5. UNIX for Dummies Questions & Answers

how to join two files using "Join" command with one common field in this problem?

file1: Toronto:12439755:1076359:July 1, 1867:6 Quebec City:7560592:1542056:July 1, 1867:5 Halifax:938134:55284:July 1, 1867:4 Fredericton:751400:72908:July 1, 1867:3 Winnipeg:1170300:647797:July 15, 1870:7 Victoria:4168123:944735:July 20, 1871:10 Charlottetown:137900:5660:July 1, 1873:2... (2 Replies)
Discussion started by: mindfreak
2 Replies

6. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

7. Shell Programming and Scripting

join (pls help on join command)

Hi, I am a new learner of join command. Some result really make me confused. Please kindly help me. input: file1: LEO oracle engineer 210375 P.Jones Office Runner ID897 L.Clip Personl Chief ID982 S.Round UNIX admin ID6 file2: Dept2C ID897 6 years Dept5Z ID982 1 year Dept3S ID6 2... (1 Reply)
Discussion started by: summer_cherry
1 Replies

8. OS X (Apple)

Command line tool to join multiple .wmv files?

I need a simple command line executable that allows me to join many wmv files into one output wmv file, preferrably in a simple way like this: wmvjoin file1.wmv file2.wmv .... > outputfile.wmv So what I want is the wmv-equivalent of mpgtx I cannot find it on internet. Thanks. (2 Replies)
Discussion started by: karman
2 Replies

9. Filesystems, Disks and Memory

using join command for files

Hi, I have to join 2 files based on two key field columns. But join command allows to give only one key column for fetching.So kindly update me whether i can compare 2 files based on two key columns or more than one key column.If so what is the syntax to compare it. With thanks in advance,... (12 Replies)
Discussion started by: subra
12 Replies
Login or Register to Ask a Question