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?

sort the two files and then diff them... or comm if you prefer the output format.

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.

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.

Sort to uniq -c. Then, you'll just grep for lines beginning with "1."

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

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

thanks guys that worked