script to compare two files of mac address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to compare two files of mac address
# 1  
Old 10-14-2008
script to compare two files of mac address

Hi

I need to write a bash shell script. I have two separate text files. One file contains a list of MAC addresses taken from a network scan, the other contains a list of MAC addresses for our currently-managed devices. How can I compare these two files, and output a list of addresses that have no corresponding device to a third text file?
# 2  
Old 10-14-2008
sort the two files and then diff them... or comm if you prefer the output format.
# 3  
Old 10-14-2008
sorting and then diffing doesnt work. I want to end up with mac addresses that exist in one file but not in the other. Diffing the two files seems to return many diffs and not the common mac addresses in both files.
# 4  
Old 10-14-2008
In that case, a small change to the previous idea... sort the files, do a uniq, and then diff -y. That should preserve the common entries, while blank lines on one or the other side, with a < or >, will show entries existing only in one file.
# 5  
Old 10-14-2008
Sort to uniq -c. Then, you'll just grep for lines beginning with "1."

Code:
cat file1 file2 | sort | uniq -c | perl -ne 'print if $_ =~ /^\s*1\s+'

# 6  
Old 10-14-2008
comm typically outputs 3 columns... lines that are in the first file, lines that are in the second file, and lines that are in both. You can suppress the output of any of these columns leaving the information you're looking for (see man comm for details).

Another alternative: grep -vf known_macs scanned_macs > unrecognised_macs
# 7  
Old 10-14-2008
thanks guys that worked
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script who maps IP with MAC address

Hy every body, Unfortunately and without success, i want to write a bash script who maps a known IP addess to a known MAC address using iptables and for the FORWARD chain. Within the DHCP server, i have assigned a fixed IP address to all clients based on their MAC addresses of their... (11 Replies)
Discussion started by: hermouche
11 Replies

2. IP Networking

MAC Address - Four Interfaces with the same MAC Address

four interfaces with ifconfig all interfaces have the same mac. If is not set for unique. but it still works. what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies

3. Red Hat

No Mac address present,

I have installed RHEL 6 in my new system. My sytem is physically also connected with network, but after successfully installing it is not detecting the network. I checked, there is no /etc/sysconfig/network file present in my system. I manually created /etc/sysconfig/network file. The problem I... (5 Replies)
Discussion started by: Ankur Goyal
5 Replies

4. Shell Programming and Scripting

Script extracting ip address from MAC wifi card

Hi Everybody, Goal: From my backup box on my local network, knowing the Wifi MAC address of my laptop, I would like to dynamically identify which ip address is attributed to my laptop. The aim is to store this ip address in a local variable and that this information is retrieved by another... (11 Replies)
Discussion started by: freddie50
11 Replies

5. IP Networking

Tracing a MAC address to IP address: Solaris

Hi there I lost connectivity to one of our remote systems and when I checked the messages log I found the following: Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1 Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies

6. SCO

MAC address

hi every one please help i want to change mac address in sco unix 5.0.6 how can i do this (3 Replies)
Discussion started by: kaydream
3 Replies

7. Solaris

Get ip address from mac address

I have following message in my messages file on solaris 10 WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
Discussion started by: fugitive
6 Replies

8. IP Networking

How to Achive IP address through MAC(Ethernet) address

Hi sir, i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address....... but i'm nt getting that how i can pass the MAC address to Frame........ Please give me an idea for making such program... Thanks & regards Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies

9. UNIX for Dummies Questions & Answers

Mac address

Hi Can some one help me How do find out Mac address in Tru64 Unix Thank you (1 Reply)
Discussion started by: Syed_45
1 Replies

10. Programming

Get Mac Address

:( Hi I am trying to get Mac address of of my Sun server from my C program running on the host machine. Any suggestions . (1 Reply)
Discussion started by: ss_hpov
1 Replies
Login or Register to Ask a Question