Comparing Files.

This is a discussion on Comparing Files. within the Tech Board forums, part of the Community Boards category; Hey guys, I have 30 files full of mac addresses. What do you think would be the best way to ...

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    5

    Comparing Files.

    Hey guys,

    I have 30 files full of mac addresses. What do you think would be the best way to compare all these files and output the mac addresses that show up in all 30 files to a new file. Is there a compare function? Should I read them into arrays and compare them? Any ideas would help out, I am a newbie to C but understand the basics. Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,854
    C compare question.
    Or is this a slightly different problem?

    If the files are text files, one MAC address per line, then I can do this using a 2-line AWK program
    Code:
    { count[$1]++ }
    END { for ( i in count ) if ( count[i] == 30 ) print i
    Save that as a file called program.

    Then do
    Code:
    awk -f program mac_file*.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    5
    Yes it is the same question, I forgot I asked here already. Thanks for your reply. I like your way of doing it.

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Posts
    463
    I would suggest separating each MAC address by strings, and using the function strcmp() to compare. If you dont know how to do this specifically, the FAQ should have all the info you need. If it doesn't, post again and I will do what I can

    [edit]
    Ahhh! Curses!
    [/edit]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 07:55 AM
  2. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 03:47 AM
  3. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 09:44 AM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21