Compare two files and merge columns in a third


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two files and merge columns in a third
# 8  
Old 04-04-2007
ANBU, can you explain why my solution won't work?
# 9  
Old 04-04-2007
Quote:
Originally Posted by CM64
Thank you, very fast and useful replay, it works.

Another question, my first script (or better Ivanov script see http://groups.google.it/group/comp.d...f5ef649d853b7c) has this structure

#!/bin/sh
#
#
Mac=".1.3.6.1.2.1.17.4.3.1.1"; Port=".1.3.6.1.2.1.17.4.3.1.2"
#
Script=`basename $0`
Host=.........
Pass=........ # SNMP community name
#
GET () { snmpwalk -Onq -c $Pass -v 1$Host| $1 sed -e s/^$1\.// -e s/\"//g |
sort ;}
JOIN () { join -o 1.2,2.2,2.3,2.4,2.5,2.6,2.7 $1 $2 | sort ;}
#
for OID in Mac Port
do eval "GET \$$OID > /tmp/${Script}\$$OID" ; done

JOIN /tmp/${Script}${Port} /tmp/${Script}${Mac} | sort -nk 1,2 >> snmp.txt


How can I substitute the variable Host with a pointer to a text file with a series of host, one per line, and produce for each one of them a file maybe in /tmp in the format IPOFSWITCH.txt?
Firstly, you didn't quote the original correctly - the way you quoted it would not have worked anyway.

Here's my attempt at correcting it - not tested:
Code:
      HostFile='pathTOhostFile'
      Pass=........    # SNMP community name
#
   GET () { 
     while read Host
     do
         snmpwalk -Onq $Host $Pass $1 | sed -e s/^$1\.// -e s/\"//g | sort
     done < "${HostFile}"
   }

# 10  
Old 04-04-2007
CM, "upd_file" is the file containing:
Port Mac
1 00:0A:0B:0C:0D:0E
....
(hundred of entries)

"master_file" is the file containing:
00:0A:0B:0C:0D:0E pcname.mydomain.tld
00:0A:0B:1C:0D:0E 1.2.3.4
# 11  
Old 04-04-2007
I've done a man egrep and indeed egrep -f canno't work in our case.

Everyway the awk solution works well. I've got the host issue to solve and my little script is ready. Of course I can make one script for every switch and then call them all in another one but is not "fairy". Someone can help this very beginning shell scripter?
# 12  
Old 04-04-2007
Quote:
Originally Posted by Shell_Life
ANBU, can you explain why my solution won't work?
Code:
$ cat file1
1 00:0A:0B:0C:0D:0E
$ cat file2
00:0A:0B:0C:0D:0E pcname.mydomain.tld
00:0A:0B:1C:0D:0E 1.2.3.4

Code:
$ egrep -f file1 file2
$

is similar to
Code:
$ egrep "1 00:0A:0B:0C:0D:0E" file2
$

Here file1 is the file which contains the pattern list which contains port followed by mac. In file2 you have mac followed by ip. In the searching file file2 you dont have port before mac
# 13  
Old 04-04-2007
No, I am sure it works but sure, I've done some changes in the original because that one doesn't work. There was an error in snmpwalk syntax (for my switch of course, for others maybe it works well), I had to specify -c and -v flag (not present in the original), some OIDS was unuseful to obtain ip/mac pair and for last I had to modify JOIN in a simpler form.

Thanks for the host construct, I'm going to try it in minutes.
# 14  
Old 04-04-2007
probably your community strings and the SNMP versions will be different based on the 'Host'.

You may want to do a 'Get' on the 'sysDescr' and depending on the output use different OIDs for different 'hosts' - just an idea.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare and merge two big CSV files

Hi all, i need help. I have two csv files with a huge amount of data. I need the first column of the first file, to be compared with the data of the second, to have at the end a file with the data not present in the second file. Example File1: (only one column) profile_id 57036226... (11 Replies)
Discussion started by: SirMannu
11 Replies

2. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

3. Shell Programming and Scripting

Compare two files and merge into third

Hello: Newbie with Awk. Trying to compare two files and merge data based on CID. Please see the input file format and desired output. Any help is appreciated. TIA Input File1 CID1 --- TYP1 --- DCN1 --- INDATE1 --- IN-DATA1 CID2 --- TYP2 --- DCN2 --- INDATE2 --- IN-DATA2 CID3 ---... (6 Replies)
Discussion started by: wincrazy
6 Replies

4. Shell Programming and Scripting

Merge columns on different files

Hello, I have two files that have this format: file 1 86.82 0.00 86.82 43.61 86.84 0.00 86.84 43.61 86.86 0.00 86.86 43.61 86.88 0.00 86.88 43.61 file 2 86.82 0.22 86.84 0.22 86.86 0.22 86.88 0.22 I would like to merge these two files such that the final file looks like... (5 Replies)
Discussion started by: kayak
5 Replies

5. Shell Programming and Scripting

Compare and Merge files

Hi All, I have two different files as shown below separated by a "|". I need to compare the first column from both the files and if they match merge both the columns. File 1 "S00172012"|"CHRONIC RENAL FAILURE"|""|"I" "S00159962"|"SUBENDO INFRC-INIT EPISD"|""|"I" "S00255303"|"BENIGN... (6 Replies)
Discussion started by: nua7
6 Replies

6. Shell Programming and Scripting

Merge columns of different files

Hi, I have tab limited file 1 and tab limited file 2 The output should contain common first column vales and corresponding 2nd column values; AND also unique first column value with corresponding 2nd column value of the file that contains it and 0 for the second file. the output should... (10 Replies)
Discussion started by: polsum
10 Replies

7. UNIX for Dummies Questions & Answers

Merge two files with two columns being similar

Hi everyone. How can I merge two files, where each file has 2 columns and the first columns in both files are similar? I want all in a file of 4 columns; join command removes the duplicate columns. 1 Dave 2 Mark 3 Paul 1 Apple 2 Orange 3 Grapes to get it like this in the 3rd file:... (9 Replies)
Discussion started by: Atrisa
9 Replies

8. Shell Programming and Scripting

merge the two files which has contain columns

Hi may i ask how to accomplish this task: I have 2 files which has multiple columns first file 1 a 2 b 3 c 4 d second file 14 a 9 .... 13 b 10.... 12 c 11... 11 d 12... I want to merge the second file to first file that will looks like this ... (2 Replies)
Discussion started by: jao_madn
2 Replies

9. UNIX for Dummies Questions & Answers

compare columns from 2 files and merge

Dear all, Being new to Unix i have a problem. I have 2 files: File 1: 118,1,0,2,3,0,5,0.3,0,0.3,0.6,1 118,2,1,2,2,0,5,0.4,0,0.4,0.4,1 118,4,2,0,3,0,5,0.7,0,0.3,0.6,1 118,6,4,1,0,0,5,0.8,0,0.2,0,1 File 2: 118,1,BFGL-NGS-109695,3610326,0,18,1,0.556,0.389,0.056,0.25,0.8183... (2 Replies)
Discussion started by: samwilkinson
2 Replies

10. Shell Programming and Scripting

compare the column from 3 files and merge that line

I have 3 file, each of has got 80000 records. file1.txt ----------------------- ABC001;active;modify;accept; ABC002;notactive;modify;accept; ABC003;notactive;no-modify;accept; ABC004;active;modify;accept; ABC005;active;no-modify;accept; file2.txt ---------------------------... (8 Replies)
Discussion started by: ganesh_mak
8 Replies
Login or Register to Ask a Question